Edit: After a number of attempts (such as using Golang's regexp library or strings.Contains()), I wasn't able to speed it up much. Interestingly, grep performs the same search in about 5ms on my machine.
Edit: After a number of attempts (such as using Golang's regexp library or strings.Contains()), I wasn't able to speed it up much. Interestingly, grep performs the same search in about 5ms on my machine.
One big takeaway is that grep doesn't simply traverse the string linearly, instead using the Boyer-Moore algorithm [2].
1: https://lists.freebsd.org/pipermail/freebsd-current/2010-Aug...
2: https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_sea...
EDIT: Interestingly, there seems to be an internal Boyer-Moore implementation in Golang's strings package[3], though it only appears to be used in strings.Replace("")[4]