Skip to content

Instantly share code, notes, and snippets.

@hakanensari
Created December 15, 2015 23:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakanensari/3dc5fa5d7e96ee9cda79 to your computer and use it in GitHub Desktop.
Save hakanensari/3dc5fa5d7e96ee9cda79 to your computer and use it in GitHub Desktop.
The cost of binding lambdas to context in Ruby
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