Last active
December 11, 2015 19:28
-
-
Save mcansky/4648380 to your computer and use it in GitHub Desktop.
This file contains 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 = 500 | |
archs = ["i486", "ia64"] | |
archs.each do |arch| | |
Benchmark.bm(7) do |x| | |
x.report("case : #{arch}") { n.times { case arch when /i\d86/ then "i386" else arch end }} | |
x.report("if (match): #{arch}") { n.times { if (arch.match(/i\d86/)) then "i386" else arch end }} | |
x.report("? (match) : #{arch}") { n.times { arch.match(/i\d86/) ? "i386" : arch }} | |
x.report("if (=~) : #{arch}") { n.times { if (arch =~ (/i\d86/)) then "i386" else arch end }} | |
x.report("? (=~) : #{arch}") { n.times { arch =~ (/i\d86/) ? "i386" : arch }} | |
end | |
end | |
# user system total real | |
# case : i486 0.000000 0.000000 0.000000 ( 0.000257) | |
# if (match): i486 0.000000 0.000000 0.000000 ( 0.000900) | |
# ? (match) : i486 0.000000 0.000000 0.000000 ( 0.000584) | |
# if (=~) : i486 0.000000 0.000000 0.000000 ( 0.000220) | |
# ? (=~) : i486 0.000000 0.000000 0.000000 ( 0.000228) | |
# user system total real | |
# case : ia64 0.000000 0.000000 0.000000 ( 0.000246) | |
# if (match): ia64 0.000000 0.000000 0.000000 ( 0.000305) | |
# ? (match) : ia64 0.000000 0.000000 0.000000 ( 0.000266) | |
# if (=~) : ia64 0.000000 0.000000 0.000000 ( 0.000209) | |
# ? (=~) : ia64 0.000000 0.000000 0.000000 ( 0.000229) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
even with n = 50000 we get something similar