[macruby-changes] [MacRuby/MacRuby] 37d1d9: improve a performance in String#index when string ...

GitHub noreply at github.com
Fri Dec 28 18:43:50 PST 2012


  Branch: refs/heads/master
  Home:   https://github.com/MacRuby/MacRuby
  Commit: 37d1d93fb97a62449f8ba1559017358ea5e164f2
      https://github.com/MacRuby/MacRuby/commit/37d1d93fb97a62449f8ba1559017358ea5e164f2
  Author: Watson <watson1978 at gmail.com>
  Date:   2012-12-28 (Fri, 28 Dec 2012)

  Changed paths:
    M string.c

  Log Message:
  -----------
  improve a performance in String#index when string is ascii code range

* before
       user     system      total        real
one      0.320000   0.000000   0.320000 (  0.312905)
small    4.330000   0.000000   4.330000 (  4.336463)

* after
       user     system      total        real
one      0.340000   0.000000   0.340000 (  0.331335)
small    1.330000   0.000000   1.330000 (  1.328736)

Test Code:
----
require 'benchmark'

str = "hoge" * 10000 + "\n"

Benchmark.bm(7) do |x|
  x.report "one" do
    10000.times do
      str.index("\n")
    end
  end

  x.report "small" do
    10000.times do
      str.index("hoge\n")
    end
  end
end





More information about the macruby-changes mailing list