Skip to content

Conversation

@ermolaev
Copy link
Contributor

class B
end

Benchmark.ips do |x|
  x.report("class_eval")         { B.class_eval("def a? = 1") }
  x.report("define_method str")  { B.define_method("#{:a}?") { 1 } }
  x.report("define_method sym")  { B.define_method(:"#{:a}?") { 1 } }
  x.compare!
end;

# Comparison:
#    define_method sym:  2324533.3 i/s
#    define_method str:  2286626.9 i/s - same-ish: difference falls within error
#           class_eval:   257038.4 i/s - 9.04x  slower

@ermolaev ermolaev merged commit 30df8f7 into master Dec 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants