Created
June 5, 2018 11:23
-
-
Save SamSaffron/805bf43016cc897c0f0c19078e7ad171 to your computer and use it in GitHub Desktop.
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/ips' | |
require 'securerandom' | |
test = (0..50).map{ SecureRandom.hex } | |
Benchmark.ips do |b| | |
b.report("map") do |i| | |
while i > 0 | |
test.map{|x| -x} | |
i -= 1 | |
end | |
end | |
b.report("colon") do |i| | |
while i > 0 | |
test.map(&:-@) | |
i -= 1 | |
end | |
end | |
end | |
# Ruby 2.5.1 | |
# Warming up -------------------------------------- | |
# map 9.729k i/100ms | |
# colon 11.385k i/100ms | |
# Calculating ------------------------------------- | |
# map 103.892k (± 4.1%) i/s - 525.366k in 5.065502s | |
# colon 122.142k (± 3.8%) i/s - 614.790k in 5.040780s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment