まつもと ゆきひろです
[ruby-talk:188721]で、以下のプログラム(特にquxと呼ばれるパター
ンにおいて)1.9(鬼車)が1.8より遅いという指摘がありました。
お知らせまで。
@re = /^\w+-\w+$/ # Some random expression
def foo(str)
str =~ @re
end
def bar(str)
str =~ /^\w+-\w+$/
end
def qux(str)
str =~ Regexp.new("/^\w+-\w+$/")
end
require 'benchmark'
include Benchmark
bm(16) do |test|
test.report("foo") do
1_000_000.times {foo("abc-xyz")}
end
test.report("bar") do
1_000_000.times {bar("abc-xyz")}
end
test.report("qux") do
1_000_000.times {qux("abc-xyz")}
end
end