Created
February 20, 2015 20:56
-
-
Save britishtea/e0bbbce9129d8c1a6b93 to your computer and use it in GitHub Desktop.
Is _ as an argument name optimized or just a convention?
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
def does_care(*a) | |
"hi" | |
end | |
def cares_a_little(*_a) | |
"hi" | |
end | |
def does_not_care(*_) | |
"hi" | |
end | |
def really_doesnt_care(*) | |
"hi" | |
end | |
require "benchmark/ips" | |
Benchmark.ips do |x| | |
x.report("*a") { does_care(1,2,3) } | |
x.report("*_a") { cares_a_little(1,2,3) } | |
x.report("*_") { does_not_care(1,2,3) } | |
x.report("*") { really_doesnt_care(1,2,3) } | |
x.compare! | |
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
Calculating ------------------------------------- | |
*a 52.377k i/100ms | |
*_a 52.644k i/100ms | |
*_ 52.383k i/100ms | |
* 52.646k i/100ms | |
------------------------------------------------- | |
*a 1.785M (± 7.2%) i/s - 8.904M | |
*_a 1.777M (±11.7%) i/s - 8.686M | |
*_ 1.810M (± 8.0%) i/s - 8.957M | |
* 1.811M (± 6.9%) i/s - 9.002M | |
Comparison: | |
*: 1811206.5 i/s | |
*_: 1809693.2 i/s - 1.00x slower | |
*a: 1784987.0 i/s - 1.01x slower | |
*_a: 1777387.3 i/s - 1.02x slower | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment