Skip to content

Instantly share code, notes, and snippets.

@tjsingleton
Last active December 15, 2015 02:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tjsingleton/5190328 to your computer and use it in GitHub Desktop.
Save tjsingleton/5190328 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
Benchmark.ips do |x|
RESULT = [1]
x.report('first') do |times|
i = 0
while i < times
id = RESULT.first
i += 1
end
end
x.report('index') do |times|
i = 0
while i < times
id = RESULT[0]
i += 1
end
end
x.report('at') do |times|
i = 0
while i < times
id = RESULT.at(0)
i += 1
end
end
x.report('multiple assignment') do |times|
i = 0
while i < times
id, _ = RESULT
i += 1
end
end
end
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
Calculating -------------------------------------
first 47576 i/100ms
index 58701 i/100ms
at 63381 i/100ms
multiple assignment 47781 i/100ms
-------------------------------------------------
first 13747991.6 (±4.9%) i/s - 68366712 in 4.991485s
index 22703483.4 (±7.6%) i/s - 112060209 in 4.989942s
at 12546992.2 (±2.6%) i/s - 62620428 in 4.995312s
multiple assignment 22409002.3 (±3.6%) i/s - 111568635 in 4.987226s
jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on Java HotSpot(TM) 64-Bit Server VM 1.6.0_43-b01-447-11M4203 [darwin-x86_64]
Calculating -------------------------------------
first 48796 i/100ms
index 58585 i/100ms
at 80813 i/100ms
multiple assignment 80660 i/100ms
-------------------------------------------------
first 28412958.4 (±39.0%) i/s - 122380368 in 4.954999s
index 25402739.2 (±23.4%) i/s - 114650845 in 4.964001s
at 24100236.8 (±16.7%) i/s - 115643403 in 4.973001s
multiple assignment 32687016.2 (±24.8%) i/s - 150672880 in 4.960000s
MacRuby 0.11 (ruby 1.9.2) [universal-darwin10.0, x86_64]
Calculating -------------------------------------
first 68024 i/100ms
index 71208 i/100ms
at 68211 i/100ms
multiple assignment 69491 i/100ms
-------------------------------------------------
first 14137655.2 (±2.5%) i/s - 70608912 in 4.997973s
index 37691986.6 (±5.3%) i/s - 186992208 in 4.993058s
at 12826278.0 (±6.1%) i/s - 63777285 in 4.998677s
multiple assignment 18764141.7 (±16.3%) i/s - 84779020 in 5.018970s
@plukevdh
Copy link

rubinius 2.0.0.rc1 (1.8.7 f915f7e4 yyyy-mm-dd JI) [x86_64-apple-darwin12.2.0]

Calculating -------------------------------------
               first    175348 i/100ms
               index    199008 i/100ms
                  at    227895 i/100ms
 multiple assignment    225671 i/100ms
-------------------------------------------------
               first 45533567.5 (±0.8%) i/s -  227601704 in   4.998850s
               index 17716844.7 (±1.1%) i/s -   88558560 in   4.999225s
                  at 66112795.4 (±1.6%) i/s -  330447750 in   4.999731s
 multiple assignment 20989946.5 (±1.0%) i/s -  104937015 in   4.999864s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment