Last active
August 29, 2015 14:06
-
-
Save ehlyzov/fae4f794f0aa7b356ec2 to your computer and use it in GitHub Desktop.
Benchmark calling speed
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
| #!/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