Substring searching in sub-linear time
blog.phusion.nl
blog.phusion.nl
http://effbot.org/zone/stringlib.htm
Here's a link to the file in the Python SVN repo:
http://svn.python.org/view/python/trunk/Objects/stringlib/fa...
https://github.com/ruby/ruby/blob/ruby_1_8_7/regex.c#L2751-2...
EDIT: Looks like 1.9 does too:
For example, if you do:
$str =~ /foobarbaz/;
perl sees what you want and uses Boyer-Moore instead of a normal regex state machine.This, and many other optimizations, is what 20 years of language development gets you.
http://ridiculousfish.com/blog/archives/2006/05/30/old-age-a...
Makes sense, as long as you and the people using the code know the tradeoffs involved.
The poor performance of Turbo Boyer-Moore might be due to cache locality issues. If you jump from checking the end of the needle to the start of the needle, then there's a good chance that you'll cause a cache miss - which has the same cost as several hundred instructions. A modern Turbo Boyer-Moore would probably work backwards within the same cache line before jumping to the start of the needle. A couple of carefully chosen cache-preload instructions could make Turbo Boyer-Moore. For a good overview of cache effects, google "gallery of processor cache effects".
The only relevant 'several hundred instructions' cache miss on a Core 2 Duo is a L2 miss ("Last Level Cache" miss). The hardware pre-fetcher will pick up accesses to the data stream after the first 1-2 misses. No amount of minor local jumping around in Turbo-BM is going to affect this.