From: brabuhr@... Date: 2010-06-25T04:02:32+09:00 Subject: Re: Count substrings in string, scan too slow On Thu, Jun 24, 2010 at 1:16 PM, Michael Fellinger wrote: > I've just run some benchmarks with strscan, and it's at least in the > same ballpark as the other approaches, unless you're on rubinius, but > then all string processing is really slow on that anyway. > > Benchmark with strscan here: http://gist.github.com/451675 http://en.literateprograms.org/Boyer-Moore_string_search_algorithm_%28Java%29 require 'java' java_import 'BoyerMoore' x.report 'boyer_moore' do count = BoyerMoore.match("yo", s).size check count end $ jruby -v yomark.rb jruby 1.5.0 (ruby 1.8.7 patchlevel 249) (2010-05-12 6769999) (Java HotSpot(TM) Client VM 1.6.0_20) [i386-java] Rehearsal ----------------------------------------------- scan 22.423000 0.000000 22.423000 ( 22.334000) scan ++ 36.738000 0.000000 36.738000 ( 36.738000) scan re 19.451000 0.000000 19.451000 ( 19.451000) scan re ++ 39.222000 0.000000 39.222000 ( 39.222000) while 22.621000 0.000000 22.621000 ( 22.622000) strscan 29.075000 0.000000 29.075000 ( 29.076000) boyer_moore 0.009000 0.000000 0.009000 ( 0.009000) ------------------------------------ total: 169.539000sec user system total real scan 18.050000 0.000000 18.050000 ( 18.051000) scan ++ 35.046000 0.000000 35.046000 ( 35.046000) scan re 17.807000 0.000000 17.807000 ( 17.807000) scan re ++ 34.086000 0.000000 34.086000 ( 34.085000) while 22.089000 0.000000 22.089000 ( 22.089000) strscan 29.538000 0.000000 29.538000 ( 29.538000) boyer_moore 0.005000 0.000000 0.005000 ( 0.004000) $ jruby -v --server --fast yomark.rb jruby 1.5.0 (ruby 1.8.7 patchlevel 249) (2010-05-12 6769999) (Java HotSpot(TM) Server VM 1.6.0_20) [i386-java] yobench.rb:50 warning: Useless use of a variable in void context. Rehearsal ----------------------------------------------- scan 17.340000 0.000000 17.340000 ( 17.154000) scan ++ 23.986000 0.000000 23.986000 ( 23.987000) scan re 15.170000 0.000000 15.170000 ( 15.169000) scan re ++ 22.805000 0.000000 22.805000 ( 22.806000) while 12.050000 0.000000 12.050000 ( 12.050000) strscan 31.396000 0.000000 31.396000 ( 31.396000) boyer_moore 0.010000 0.000000 0.010000 ( 0.010000) ------------------------------------ total: 122.756999sec user system total real scan 15.201000 0.000000 15.201000 ( 15.201000) scan ++ 23.758000 0.000000 23.758000 ( 23.758000) scan re 14.770000 0.000000 14.770000 ( 14.770000) scan re ++ 22.455000 0.000000 22.455000 ( 22.455000) while 12.182000 0.000000 12.182000 ( 12.182000) strscan 24.497000 0.000000 24.497000 ( 24.497000) boyer_moore 0.002000 0.000000 0.002000 ( 0.002000)