Skip to content

Instantly share code, notes, and snippets.

@dbussink
Created March 5, 2013 15:08
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/91ebcb535f73ef2de412 to your computer and use it in GitHub Desktop.
Save dbussink/91ebcb535f73ef2de412 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
class Foo
define_method("foo") { }
class_eval 'def bar; end'
end
Benchmark.ips do |x|
foo = Foo.new
x.report("class_eval") { foo.bar }
x.report("define_method") { foo.foo }
end
class_eval 6874955.4 (±1.0%) i/s - 34395821 in 5.003561s (cycle=205963)
define_method 6187071.9 (±1.7%) i/s - 30989768 in 5.010413s (cycle=289624)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment