Hello,
I was reading the pickaxe book and then I arrived to the chapter
“When trouble strikes” in the Benchmark section.
I have this code:
#!/usr/bin/ruby -w
require ‘benchmark’
include Benchmark
LOOP_COUNT = 1_000_000
bm(12) do |test|
test.report(“normal:”) do
LOOP_COUNT.times do |x|
y = x +1
end
end
test.report(“predefine:”) do
x = y = 0
LOOP_COUNT.times do |x|
y = x + 1
end
end
end
The “predefine” test is more fast than the “normal”. Why?
The only difference that I see is x = y = 0 but I don’t understand
thanks!
Rafael G.