Created
October 16, 2013 08:48
-
-
Save lulalala/7004688 to your computer and use it in GitHub Desktop.
Using splat to accept large array is slow.
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' | |
| iterations = 100_000 | |
| def a(*args) | |
| args.size | |
| end | |
| def b(args) | |
| args.size | |
| end | |
| big_array = (1..100).to_a | |
| Benchmark.bmbm do |bm| | |
| bm.report('use splat') do | |
| iterations.times do | |
| a(*big_array) | |
| end | |
| end | |
| bm.report('pass array') do | |
| iterations.times do | |
| b(big_array) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment