Skip to content

Instantly share code, notes, and snippets.

@schneems
Last active December 19, 2015 04:28
Show Gist options
  • Select an option

  • Save schneems/5897076 to your computer and use it in GitHub Desktop.

Select an option

Save schneems/5897076 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
class Foo
def bar
rand(5) + 1
end
end
foo = Foo.new
Benchmark.ips do |bench|
bench.report("send string") {foo.send("bar")}
bench.report("send symbol") {foo.send(:"bar")}
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