Created
September 1, 2020 11:02
-
-
Save charlespeach/526930ca083d7b3d006cb2e6be291cc6 to your computer and use it in GitHub Desktop.
Benchmarking string concat from array of hashes
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' | |
Benchmark.ips do |b| | |
b.config(time: 39, warmup: 2) | |
count = 100 | |
ary = Array.new(count, { text: 'text' }) | |
b.report("map") do | |
ary.map { |hash| hash[:text] }.join | |
end | |
b.report("inject") do | |
ary.inject(String.new) { |memo, hash| memo << hash[:text] } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment