Skip to content

Instantly share code, notes, and snippets.

@splattael
Forked from schneems/gist:5897076
Last active December 19, 2015 04:48
Show Gist options
  • Save splattael/5899463 to your computer and use it in GitHub Desktop.
Save splattael/5899463 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
class Foo
def bar
1
end
end
foo = Foo.new
string_method = "bar"
symbol_method = :"bar"
Benchmark.ips do |bench|
bench.report("send string") {foo.send(string_method)}
bench.report("send symbol") {foo.send(symbol_method)}
end
# Ruby 2.0.0
# Calculating -------------------------------------
# send string 43864 i/100ms
# send symbol 57938 i/100ms
# -------------------------------------------------
# send string 1373253.2 (±16.4%) i/s - 6667328 in 5.002895s
# send symbol 1799751.7 (±9.3%) i/s - 8922452 in 5.000714s
# Ruby 1.9.3
# Calculating -------------------------------------
# send string 45224 i/100ms
# send symbol 58638 i/100ms
# -------------------------------------------------
# send string 1358732.7 (±8.1%) i/s - 6783600 in 5.030276s
# send symbol 2094714.2 (±6.7%) i/s - 10437564 in 5.008017s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment