On Sat, 2022-05-07 at 15:18 -0700, Amnon wrote:
> The other interesting question is what algorithm we use to find the
> pattern in each line.
> Generally bytes.Contains uses Rabin-Karp. But as the pattern is the
> word "test" which is only 4 bytes long,
> a brute force search is used, using SSE type instructions where
> available.
> So the naive Go approach will give you a very fast execution. The
> main thing is to set up your scanner with a large buffer, to minimize
> the number
> of file system reads, and to avoid the newbie error of working with
> strings rather than []byte, and forcing the code to do vast numbers
> of
> unnecessary and expensive allocations.

There is an interesting post from the author of grep that goes over
some of these details
https://lists.freebsd.org/pipermail/freebsd-current/2010-August/019310.html
.


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/27eef405ac38a8e32488f15ee7726c3478866ede.camel%40kortschak.io.

Reply via email to