Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- class Clock
- def on!
- 1 + 2
- end
- define_method(:off!) do
- 1 + 2
- end
- end
- class AnotherClock < Clock
- def on!
- super + 3
- end
- define_method(:off!) do
- super() + 3
- end
- end
- def func
- 1 + 2
- end
- def another_func
- func + 3
- end
- N = 1000000
- clock = Clock.new
- another_clock = AnotherClock.new
- Benchmark.bm(20) do |x|
- x.report("Clock#on!") { N.times { clock.on! } }
- x.report("AnotherClock#on!") { N.times { another_clock.on! } }
- x.report("Clock#off!") { N.times { clock.off! } }
- x.report("AnotherClock#off!") { N.times { another_clock.off! } }
- x.report("func") { N.times { func } }
- x.report("another_func") { N.times { another_func } }
- end
Add Comment
Please, Sign In to add comment