Created
July 8, 2015 11:09
-
-
Save solnic/d217443700bc84cb9bcd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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