Why GNU grep is fast (2010)

Why GNU grep is fast (2010)

GNU grep uses raw Unix input system calls and avoids copying data
after reading it. So instead of using line-oriented input, GNU grep reads raw data into
a large buffer, searches the buffer using Boyer-Moore, and only when
it finds a match does it go and look for the bounding newlines. Finally, when I was last the maintainer of GNU grep (15+ years ago…),
GNU grep also tried very hard to set things up so that the *kernel*
could ALSO avoid handling every byte of the input, by using mmap()
instead of read() for file input.

Source: lists.freebsd.org