Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created July 18, 2011 15:04
Show Gist options
  • Save jonleighton/1089783 to your computer and use it in GitHub Desktop.
Save jonleighton/1089783 to your computer and use it in GitHub Desktop.
Proving to myself that it really is faster to avoid using send...
# 1.9.2
Rehearsal -------------------------------------------------------
no-send 1.950000 0.000000 1.950000 ( 1.961587)
symbol-send 2.190000 0.000000 2.190000 ( 2.192600)
string-send 4.790000 0.000000 4.790000 ( 4.812341)
---------------------------------------------- total: 8.930000sec
user system total real
no-send 2.330000 0.000000 2.330000 ( 2.332294)
symbol-send 3.510000 0.010000 3.520000 ( 3.529359)
string-send 8.030000 0.000000 8.030000 ( 8.076293)
# 1.8.7
Rehearsal -------------------------------------------------------
no-send 2.800000 0.000000 2.800000 ( 2.812871)
symbol-send 3.550000 0.000000 3.550000 ( 3.561249)
string-send 6.210000 0.000000 6.210000 ( 6.234676)
--------------------------------------------- total: 12.560000sec
user system total real
no-send 4.700000 0.000000 4.700000 ( 4.726431)
symbol-send 5.790000 0.000000 5.790000 ( 5.813629)
string-send 7.460000 0.000000 7.460000 ( 7.495963)
require 'benchmark'
def foo
"bar"
end
n = 10_000_000
Benchmark.bmbm(20) do |b|
b.report('no-send') do
n.times { foo }
end
b.report('symbol-send') do
n.times { send(:foo) }
end
b.report('string-send') do
n.times { send('foo') }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment