Skip to content

Instantly share code, notes, and snippets.

@tatey
Created January 11, 2010 05:46
Show Gist options
  • Save tatey/274015 to your computer and use it in GitHub Desktop.
Save tatey/274015 to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 20000
Benchmark.bm do |b|
b.report { n.times do; n == 1 or n == 2 or n == 3 or n == 5 or n == 6 or n == 7 or n == 8 or n == 9 or n == 10; end }
b.report { n.times do; [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].include?(n); end }
end
# $ ruby test.rb
# user system total real
# 0.030000 0.000000 0.030000 ( 0.029940)
# 0.030000 0.000000 0.030000 ( 0.030755)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment