Skip to content

Instantly share code, notes, and snippets.

@edymerchk
Last active December 24, 2015 00:19
Show Gist options
  • Save edymerchk/6715980 to your computer and use it in GitHub Desktop.
Save edymerchk/6715980 to your computer and use it in GitHub Desktop.
%w(…) VS array [..]
require 'benchmark'
n = 10000000
Benchmark.bm(10) do |b|
b.report('%w') { n.times { %w[hugo paco luis] } }
b.report('explicit') { n.times { ['hugo', 'paco', 'luis'] } }
end
# Test 1:
# user system total real
# %w 3.160000 0.000000 3.160000 ( 3.158635)
# explicit 3.160000 0.000000 3.160000 ( 3.159078)
# Test 2:
# user system total real
# %w 3.170000 0.000000 3.170000 ( 3.169868)
# explicit 3.160000 0.000000 3.160000 ( 3.156675)
# Tet 3:
# user system total real
# %w 3.250000 0.000000 3.250000 ( 3.245555)
# explicit 3.230000 0.000000 3.230000 ( 3.234404)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment