Created
October 2, 2011 19:07
-
-
Save Bodacious/1257790 to your computer and use it in GitHub Desktop.
Benchmark comparing class_eval to define_method when defining methods
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" | |
COUNT = 1000 | |
Benchmark.bmbm do |test| | |
test.report "class eval" do | |
class ClassEvalClass;end | |
COUNT.times do |i| | |
ClassEvalClass.send :class_eval, "def method_no_#{i}; return #{i} ;end" | |
d = ClassEvalClass.new | |
d.send("method_no_#{i}") | |
end | |
end | |
test.report "define_m" do | |
class DefineMClass;end | |
COUNT.times do |i| | |
DefineMClass.send :define_method, "method_no_#{i}" do | |
return i | |
end | |
d = DefineMClass.new | |
d.send("method_no_#{i}") | |
end | |
end | |
end |
Author
Bodacious
commented
Oct 2, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment