Created
October 27, 2009 02:56
-
-
Save thumblemonks/219259 to your computer and use it in GitHub Desktop.
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' | |
class Foo | |
def a; true; end | |
end | |
n = 1_000_000 | |
Benchmark.bm(30) do | b | | |
instance = Foo.new | |
b.report( "a simple method call" ) do | |
n.times { instance.a } | |
end | |
instance = Foo.new | |
block = lambda { true } | |
b.report( "instance_eval with block" ) do | |
n.times { instance.instance_eval( &block ) } | |
end | |
instance = Foo.new | |
string = "true" | |
b.report( "instance_eval with string" ) do | |
n.times { instance.instance_eval( string ) } | |
end | |
method = Foo.instance_method( :a ) | |
instance = Foo.new | |
bound_method = method.bind( instance ) | |
b.report( "bound method" ) do | |
n.times { bound_method.call } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment