Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
Created June 5, 2018 11:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamSaffron/805bf43016cc897c0f0c19078e7ad171 to your computer and use it in GitHub Desktop.
Save SamSaffron/805bf43016cc897c0f0c19078e7ad171 to your computer and use it in GitHub Desktop.
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