Skip to content

Instantly share code, notes, and snippets.

@ehlyzov
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save ehlyzov/fae4f794f0aa7b356ec2 to your computer and use it in GitHub Desktop.

Select an option

Save ehlyzov/fae4f794f0aa7b356ec2 to your computer and use it in GitHub Desktop.
Benchmark calling speed
#!/usr/bin/env ruby
require 'benchmark/ips'
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
def block_call &block
block.call
end
def block_yield
yield
end
x.report("block call") { block_call {} }
x.report("block yield") { block_yield {} }
x.report("proc call") { proc {}.call }
x.report("lambda call") { -> {}.call }
x.report("call Lambda as block") { block_call &->{} }
x.report("yield lambda as block") { block_yield &->{} }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment