2 ms·
> that just has to be several times slower This is why Matz gave us benchmark: steve at thoth in ~/tmp $ cat benchmark.rb require 'benchmark'
by steveklabnik 14y ago
> that just has to be several times slower
This is why Matz gave us benchmark:
steve at thoth in ~/tmp
$ cat benchmark.rb
require 'benchmark'
n = 500000
Benchmark.bm do |x|
x.report("==") do
n.times do
foo = "lol"
foo == "bar" || foo == "baz" || foo == :sed || foo == 5
end
end
x.report("include?") do
n.times do
foo = "lol"
["bar", "baz", :sed, 5].include?(foo)
end
end
end
steve at thoth in ~/tmp
$ ruby benchmark.rb
user system total real
== 0.370000 0.000000 0.370000 ( 0.367943)
include? 0.550000 0.000000 0.550000 ( 0.551897)
- cheald 14y agoNow do it enough to trigger a couple of GC passes, and the #include? version looks even worse.