Created
December 15, 2015 23:49
-
-
Save hakanensari/3dc5fa5d7e96ee9cda79 to your computer and use it in GitHub Desktop.
The cost of binding lambdas to context in Ruby
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' | |
foo = -> {} | |
_ = BasicObject.new | |
def _.bar | |
end | |
n = 4_000_000 | |
Benchmark.bm(7) do |x| | |
x.report("context") { n.times { foo.call } } | |
x.report("none") { n.times { _.bar } } | |
end | |
# user system total real | |
# context 0.630000 0.010000 0.640000 ( 0.647041) | |
# none 0.390000 0.000000 0.390000 ( 0.395646) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment