Skip to content

Instantly share code, notes, and snippets.

@caius
Last active November 16, 2022 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caius/e8f7ab2827b0273690b902a71eb4ae02 to your computer and use it in GitHub Desktop.
Save caius/e8f7ab2827b0273690b902a71eb4ae02 to your computer and use it in GitHub Desktop.
require "benchmark/ips"
Benchmark.ips do |b|
b.report("Array.new block") do
Array.new(100) { 10 }
end
b.report("Array.new argument") do
Array.new(100, 10)
end
b.report("times.map") do
100.times.map { 10 }
end
end
__END__
================================================================================
2022-11-16 at 14:13:37
~/code/relayplatform/api/tmp/bench-array-new-times-map.rb
--------------------------------------------------------------------------------
Warming up --------------------------------------
Array.new block 41.360k i/100ms
Array.new argument 770.889k i/100ms
times.map 29.598k i/100ms
Calculating -------------------------------------
Array.new block 411.852k (± 0.8%) i/s - 2.068M in 5.021585s
Array.new argument 7.719M (± 2.2%) i/s - 39.315M in 5.096243s
times.map 294.264k (± 1.6%) i/s - 1.480M in 5.030454s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment