Created
April 30, 2012 17:04
-
-
Save gstark/2560033 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' | |
n = 5_000_000 | |
find = 4 | |
array = [1,2,3,4] | |
Benchmark.bm do |x| | |
x.report { n.times { array.include?(4) } } | |
x.report { n.times { array.include?(5) } } | |
x.report { n.times { [1,2,3,4].include?(5) } } | |
x.report { n.times { 1 == 4 || 2 == 4 || 3 == 4 || 4 == 4 } } | |
x.report { n.times { 1 == 5 || 2 == 5 || 3 == 5 || 4 == 5 } } | |
end |
Timings for 1.9.2-p290
user system total real
1.320000 0.000000 1.320000 ( 1.322715)
1.640000 0.000000 1.640000 ( 1.640241)
3.100000 0.000000 3.100000 ( 3.103725)
0.730000 0.000000 0.730000 ( 0.722133)
0.720000 0.000000 0.720000 ( 0.721763)
Timings for JRuby 1.6.7
user system total real
0.509000 0.000000 0.509000 ( 0.409000)
0.366000 0.000000 0.366000 ( 0.366000)
0.477000 0.000000 0.477000 ( 0.477000)
0.340000 0.000000 0.340000 ( 0.340000)
0.350000 0.000000 0.350000 ( 0.350000)
Rubinius 1.2.4
user system total real
0.828770 0.000208 0.828978 ( 0.813985)
0.904801 0.000141 0.904942 ( 0.881268)
1.218347 0.002241 1.220588 ( 1.213114)
0.178378 0.000072 0.178450 ( 0.175361)
0.183385 0.000053 0.183438 ( 0.180725)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Timings for 1.8.7-p357