Skip to content

Instantly share code, notes, and snippets.

@0x0dea
Created July 2, 2015 03:30
Show Gist options
  • Save 0x0dea/1fb2ef1796ce4a3e8dc5 to your computer and use it in GitHub Desktop.
Save 0x0dea/1fb2ef1796ce4a3e8dc5 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
Benchmark.ips do |b|
n = '42'
b.report('method call') { n.to_i }
bound = n.method(:to_i)
b.report('bound') { bound.call }
unbound = String.instance_method(:to_i)
b.report('unbound') { unbound.bind(n).call }
b.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment