Skip to content

Instantly share code, notes, and snippets.

@rahul100885
Created December 13, 2011 17:32
Show Gist options
  • Save rahul100885/1473045 to your computer and use it in GitHub Desktop.
Save rahul100885/1473045 to your computer and use it in GitHub Desktop.
require "benchmark"
val = (1..9).to_a
Benchmark.bm(7) do |x|
x.report("if:") {
val.each { |v|
if v == 9
a = 9
elsif v == 8
a = 8
elsif v == 7
a = 7
elsif v == 6
a = 6
elsif v == 5
a = 5
elsif v == 4
a = 4
elsif v == 3
a = 3
elsif v == 2
a = 2
elsif v == 1
a = 1
else
a = ""
end
}
}
x.report("case:") {
val.each { |v|
case v
when 9
a = 9
when 8
a = 8
when 7
a = 7
when 6
a = 6
when 5
a = 5
when 4
a = 4
when 3
a = 3
when 2
a = 2
when 1
a = 1
else
a = ""
end
}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment