Skip to content

Instantly share code, notes, and snippets.

@marocchino
Created August 14, 2015 02:56
Show Gist options
  • Save marocchino/f8e157eee14967a1b36e to your computer and use it in GitHub Desktop.
Save marocchino/f8e157eee14967a1b36e to your computer and use it in GitHub Desktop.
Array#* vs Array.new
require 'benchmark'
n = 500_000_000_000_000
Benchmark.bm do |x|
x.report { ["a"] * 10 }
x.report { Array.new(10, "a") }
end
# user system total real
# 0.000000 0.000000 0.000000 ( 0.000012)
# 0.000000 0.000000 0.000000 ( 0.000007)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment