Skip to content

Instantly share code, notes, and snippets.

@solnic
Created July 8, 2015 11:09
Show Gist options
  • Select an option

  • Save solnic/d217443700bc84cb9bcd to your computer and use it in GitHub Desktop.

Select an option

Save solnic/d217443700bc84cb9bcd to your computer and use it in GitHub Desktop.
Calculating -------------------------------------
method 97.664k i/100ms
proc 85.151k i/100ms
-------------------------------------------------
method 2.611M (± 3.7%) i/s - 13.087M
proc 1.910M (± 3.4%) i/s - 9.537M
Comparison:
method: 2611065.1 i/s
proc: 1909549.3 i/s - 1.37x slower
require 'benchmark/ips'
module Fns
def self.upcase(input)
input.upcase
end
end
meth_obj = Fns.method(:upcase)
proc_obj = Fns.method(:upcase).to_proc
Benchmark.ips do |x|
x.report('method') { meth_obj.call('foo') }
x.report('proc') { proc_obj.call('foo') }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment