-
-
Save dbussink/700a1d13d6ca8cf44469 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/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