Nick Craver tweets out snippets of the Stack Overflow code base occasionally. About a week ago he showed off a ContainsToken method which has been tuned for performance. This set off a little bit of a benchmarking contest. My final attempt (which is among the fastest) ended up using a lot of tricks, which I think may be of general interest – so I’m going to walk through how the code works.
An Optimization Exercise
![Article hero image](https://cdn.stackoverflow.co/images/jo7n4k8s/production/ed9b76801d6f22cd8a3e351d86814cb539468d2e-1920x1081.png?rect=0,37,1920,1008&w=1200&h=630&auto=format&dpr=2)