-
-
Save ukstv/6db4ba04e8f9cb2c56641005dd188237 to your computer and use it in GitHub Desktop.
Results of a splat call benchmark
This file contains 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 = 10_000_000 | |
def splat(*args) | |
args.first | |
end | |
def nosplat(args) | |
args.first | |
end | |
Benchmark.bm do |bm| | |
bm.report("Using the splat operator") do | |
iterations.times do | |
splat(1) | |
splat([1, 2, 3, 4, 5, 6]) | |
end | |
end | |
bm.report("Using sequence of params") do | |
iterations.times do | |
nosplat([1]) | |
nosplat([1, 2, 3, 4, 5 ,6]) | |
end | |
end | |
end |
This file contains 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
user system total real | |
Using the splat operator 4.930000 0.010000 4.940000 ( 4.950988) | |
Using sequence of params 4.130000 0.010000 4.140000 ( 4.148014) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment