From: "Radosław Bułat" Date: 2008-02-12T05:41:21+09:00 Subject: Re: very bad character performance on ruby1.9 I have something similar to this problem. #======== require "benchmark" def longest_repeated_substring(s) found = nil 1.upto(s.size / 2) do |n| (s.size - n).times do |i| sub = s.slice(i, n) if s.index(sub, i + n) # > marks[i] ? i + n : marks[i]) found = sub break end end if found.nil? || found.size < n break end end return found end system("wget http://www.gnu.org/licenses/gpl-2.0.txt") unless File.exists?("gpl-2.0.txt") Benchmark.bmbm do |make| make.report do longest_repeated_substring(ARGV[0] || File.read("gpl-2.0.txt")) end end #=======end Benchmarks shows that running it on ruby1.9 is about 15x slower that ruby1.8. There is outputs (I removed ) from profiling it (-rprofile): #ruby1.8 % cumulative self self total time seconds seconds calls ms/call ms/call name 56.50 3.00 3.00 120 25.00 44.00 Integer#times 29.38 4.56 1.56 42250 0.04 0.04 String#index 7.72 4.97 0.41 42250 0.01 0.01 String#slice 5.84 5.28 0.31 42252 0.01 0.01 Fixnum#+ 0.38 5.30 0.02 2 10.00 2650.00 Integer#upto 0.19 5.31 0.01 21 0.48 0.48 String#gsub! #ruby1.9 % cumulative self self total time seconds seconds calls ms/call ms/call name 0.13 0.06 0.03 242 0.12 0.12 String#size 1.05 0.30 0.24 42252 0.01 0.01 Fixnum#+ 5.71 1.61 1.31 2 655.00 10375.00 Integer#times 43.79 11.65 10.04 42250 0.24 0.24 String#slice 48.76 22.83 11.18 42250 0.26 0.26 String#index It looks like the problem is in String#slice and String#index methods. -- Rados�aw Bu�at http://radarek.jogger.pl - m�j blog