Skip to content

Instantly share code, notes, and snippets.

@dbussink
Created March 5, 2013 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbussink/700a1d13d6ca8cf44469 to your computer and use it in GitHub Desktop.
Save dbussink/700a1d13d6ca8cf44469 to your computer and use it in GitHub Desktop.
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