Skip to content

Instantly share code, notes, and snippets.

@headius
Forked from jonleighton/benchmark.rb
Created January 19, 2012 14:12
Show Gist options
  • Save headius/1640205 to your computer and use it in GitHub Desktop.
Save headius/1640205 to your computer and use it in GitHub Desktop.
# gem install benchmark_suite
require 'benchmark/ips'
class Foo1
def foo
"bar"
end
def foo_call
foo
end
end
class Foo2 < Foo1
def foo
super()
end
def foo_call
foo
end
end
class Foo2ZSuper < Foo1
def foo
super
end
end
module Other
def foo
"bar"
end
end
class Foo2Included
include Other
def foo
super()
end
def foo_call
foo
end
end
class Foo2IncludedZSuper
include Other
def foo
super
end
end
Benchmark.ips do |r|
foo1 = Foo1.new
foo2 = Foo2.new
foo2z = Foo2ZSuper.new
foo2i = Foo2Included.new
foo2iz = Foo2IncludedZSuper.new
r.report('control') do |n|
n.times { foo1 }
end
r.report('call') do |n|
n.times { foo1.foo }
end
r.report('call from same class') do |n|
n.times { foo1.foo_call }
end
r.report('call from subclass') do |n|
n.times { foo2.foo_call }
end
r.report('super from subclass') do |n|
n.times { foo2.foo }
end
r.report('zsuper from subclass') do |n|
n.times { foo2z.foo }
end
r.report('call from includer') do |n|
n.times { foo2i.foo_call }
end
r.report('super from includer') do |n|
n.times { foo2i.foo }
end
r.report('zsuper from includer') do |n|
n.times { foo2iz.foo }
end
end
system ~/projects/jruby/gist-1640205 $ jruby -v --server -rubygems benchmark.rb
jruby 1.7.0.dev (ruby-1.8.7-p357) (2012-01-19 02a0168) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
control 33483240.7 (±4.5%) i/s - 166031140 in 4.982449s (cycle=64780)
call 15254937.7 (±5.0%) i/s - 75887588 in 4.990673s (cycle=74254)
call from same class 10774596.1 (±4.3%) i/s - 53716516 in 4.996265s (cycle=70126)
call from subclass 8582834.0 (±4.8%) i/s - 42750881 in 4.995250s (cycle=67751)
super from subclass 9829902.1 (±5.3%) i/s - 48894300 in 4.991300s (cycle=69849)
zsuper from subclass 9132835.2 (±5.2%) i/s - 45419614 in 4.989866s (cycle=70309)
call from includer 8337698.5 (±7.0%) i/s - 41382627 in 4.995220s (cycle=66001)
super from includer 9952312.4 (±5.0%) i/s - 49542165 in 4.993507s (cycle=64761)
zsuper from includer 9143720.7 (±5.1%) i/s - 45527840 in 4.994840s (cycle=67952)
system ~/projects/jruby/gist-1640205 $ pickjdk 6
New JDK: 1.7.0u.jdk
system ~/projects/jruby/gist-1640205 $ jruby -v --server -rubygems benchmark.rb
jruby 1.7.0.dev (ruby-1.8.7-p357) (2012-01-19 02a0168) (OpenJDK 64-Bit Server VM 1.7.0-u2-b21) [darwin-amd64-java]
control 35609992.5 (±5.1%) i/s - 175179152 in 4.953589s (cycle=53392)
call 22001980.1 (±5.4%) i/s - 109188588 in 4.984873s (cycle=142917)
call from same class 21756807.3 (±6.1%) i/s - 107956017 in 4.987643s (cycle=140751)
call from subclass 13572134.0 (±5.2%) i/s - 67552870 in 4.993799s (cycle=125330)
super from subclass 13008568.0 (±3.9%) i/s - 64817760 in 4.992279s (cycle=128352)
zsuper from subclass 11857333.3 (±4.5%) i/s - 59094084 in 4.995389s (cycle=134918)
call from includer 13446703.0 (±6.0%) i/s - 64908480 in 4.990150s (cycle=135226)
super from includer 12637357.3 (±4.9%) i/s - 62900370 in 4.992724s (cycle=130770)
zsuper from includer 10969694.9 (±7.2%) i/s - 54352207 in 4.990915s (cycle=134869)
system ~/projects/jruby/gist-1640205 $ rvm 1.9.3 do ruby -rubygems benchmark.rb
control 19140379.4 (±3.7%) i/s - 95488848 in 4.998993s (cycle=74952)
call 5689994.9 (±4.8%) i/s - 28402488 in 5.005694s (cycle=66987)
call from same class 4319850.3 (±4.0%) i/s - 21576402 in 5.003740s (cycle=64794)
call from subclass 3643588.3 (±3.9%) i/s - 18193555 in 5.001970s (cycle=59651)
super from subclass 4598955.6 (±4.0%) i/s - 22967232 in 5.003179s (cycle=62752)
zsuper from subclass 4595192.8 (±4.5%) i/s - 22922214 in 5.000849s (cycle=62629)
call from includer 3632468.7 (±3.6%) i/s - 18148415 in 5.003532s (cycle=59503)
super from includer 4589971.1 (±4.0%) i/s - 22909239 in 5.000413s (cycle=59197)
zsuper from includer 4536699.7 (±4.6%) i/s - 22655550 in 5.005895s (cycle=62070)
system ~/projects/jruby/gist-1640205 $ ../../rubinius/bin/rbx -v -rubygems benchmark.rb
rubinius 2.0.0dev (1.8.7 9c853513 yyyy-mm-dd JI) [x86_64-apple-darwin10.8.0]
control 74588822.0 (±4.7%) i/s - 368322488 in 4.954053s (cycle=49559)
call 18951778.7 (±5.4%) i/s - 93971113 in 4.979576s (cycle=64763)
call from same class 16911131.2 (±4.0%) i/s - 84073446 in 4.982241s (cycle=65022)
call from subclass 8539707.4 (±3.4%) i/s - 42529360 in 4.987913s (cycle=56555)
super from subclass 8850029.0 (±9.3%) i/s - 43475580 in 4.983637s (cycle=58910)
zsuper from subclass 4644906.1 (±3.5%) i/s - 23136942 in 4.988667s (cycle=53682)
call from includer 9247736.2 (±3.6%) i/s - 46061433 in 4.989120s (cycle=60687)
super from includer 10013857.4 (±2.6%) i/s - 49918804 in 4.988641s (cycle=61934)
zsuper from includer 4558668.3 (±4.5%) i/s - 22689387 in 4.990417s (cycle=54411)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment