Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:700a1d13d6ca8cf44469
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
require 'benchmark/ips'
 
class Foo
define_method("foo") { }
class_eval 'def bar; end'
 
def inline_foo
foo
foo
foo
foo
foo
end
 
def inline_bar
bar
bar
bar
bar
bar
end
end
 
Benchmark.ips do |x|
foo = Foo.new
x.report("class_eval") { foo.inline_bar }
x.report("define_method") { foo.inline_foo }
end
 
class_eval 6801365.4 (±1.1%) i/s - 34000866 in 4.999752s (cycle=203598)
define_method 4382386.9 (±2.1%) i/s - 21982388 in 5.018583s (cycle=238939)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.