Created
October 25, 2017 06:08
-
-
Save bibendi/dfea7f33ec61db85b4dc895e5c68456c to your computer and use it in GitHub Desktop.
Compare map vs map!
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
key = "id".freeze | |
rows = [] | |
5000.times { rows << {"id" => rand(5000).to_s} } | |
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
x.report('map') { rows.dup.map { |r| r[key].to_i } } | |
x.report('map!') { rows.dup.map! { |r| r[key].to_i } } | |
x.compare! | |
end | |
require 'benchmark/memory' | |
Benchmark.memory do |x| | |
x.report('map') { rows.dup.map { |r| r[key].to_i } } | |
x.report('map!') { rows.dup.map! { |r| r[key].to_i } } | |
x.compare! | |
end |
Author
bibendi
commented
Oct 25, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment