Skip to content

Instantly share code, notes, and snippets.

@gstark
Created April 30, 2012 17:04
Show Gist options
  • Save gstark/2560033 to your computer and use it in GitHub Desktop.
Save gstark/2560033 to your computer and use it in GitHub Desktop.
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
@gstark
Copy link
Author

gstark commented Apr 30, 2012

Timings for 1.8.7-p357

      user     system      total        real
  1.850000   0.000000   1.850000 (  1.856242)
  2.140000   0.000000   2.140000 (  2.136590)
  3.540000   0.010000   3.550000 (  3.544581)
  2.920000   0.000000   2.920000 (  2.919387)
  2.890000   0.000000   2.890000 (  2.882645)

@gstark
Copy link
Author

gstark commented Apr 30, 2012

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)

@gstark
Copy link
Author

gstark commented Apr 30, 2012

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)

@gstark
Copy link
Author

gstark commented Apr 30, 2012

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