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 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