Skip to content

Instantly share code, notes, and snippets.

@RunsFor
Last active February 1, 2016 22:04
Show Gist options
  • Select an option

  • Save RunsFor/1da01606f479ba75b08f to your computer and use it in GitHub Desktop.

Select an option

Save RunsFor/1da01606f479ba75b08f to your computer and use it in GitHub Desktop.
jruby perform too slow comparing to mri
require 'benchmark'
objects = nil
puts(Benchmark.measure do
objects = 100_000.times.map { Object.new }
block = proc { nil }
objects.each { |obj| obj.define_singleton_method(:test_me, &block) }
end)
puts(Benchmark.measure do
objects.each(&:test_me)
end)
@RunsFor

RunsFor commented Feb 1, 2016

Copy link
Copy Markdown
Author
⇒  ruby -v define_singleton_method_jruby.rb
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
  0.170000   0.020000   0.190000 (  0.188074)
  0.010000   0.000000   0.010000 (  0.014196)
⇒  ruby -v define_singleton_method_jruby.rb
jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit Server VM 25.72-b15 on 1.8.0_72-b15 +jit [darwin-x86_64]
  8.690000   0.170000   8.860000 (  1.356160)
  0.100000   0.000000   0.100000 (  0.056539)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment