Created
December 29, 2012 20:01
-
-
Save oscardelben/4409049 to your computer and use it in GitHub Desktop.
Another useless benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
puts "*** without send ***" | |
puts RubyVM::InstructionSequence.compile('"foo" * 3').disasm | |
puts | |
puts( Benchmark.measure do | |
10_000_000.times do | |
"foo" | |
end | |
end) | |
puts "*** with send ***" | |
def calculate | |
"foo" | |
end | |
puts RubyVM::InstructionSequence.compile('calculate').disasm | |
puts | |
puts( Benchmark.measure do | |
10_000_000.times do | |
calculate | |
end | |
end) | |
OUTPUT: | |
*** without send *** | |
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
0000 trace 1 ( 1) | |
0002 putstring "foo" | |
0004 leave | |
1.440000 0.000000 1.440000 ( 1.442240) | |
*** with send *** | |
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
0000 trace 1 ( 1) | |
0002 putself | |
0003 send :calculate, 0, nil, 24, <ic:0> | |
0009 leave | |
2.060000 0.000000 2.060000 ( 2.062916) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment