Last active
December 15, 2015 02:49
-
-
Save tjsingleton/5190328 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 |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 |
This file contains hidden or 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
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
commented
Mar 18, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment