Created
October 3, 2010 04:03
-
-
Save myronmarston/608250 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
$ ruby start_with_benchmark.rb | |
user system total real | |
start_with? fail 0.520000 0.000000 0.520000 ( 0.519693) | |
=~ fail 0.220000 0.000000 0.220000 ( 0.220458) | |
start_with? pass 0.880000 0.000000 0.880000 ( 0.887475) | |
=~ pass 0.610000 0.000000 0.610000 ( 0.608715) |
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' | |
times = 1000000 | |
string = "this is a string" | |
Benchmark.bm(16) do |x| | |
x.report("start_with? fail") do | |
times.times do | |
string.start_with?("thit") | |
end | |
end | |
x.report("=~ fail") do | |
times.times do | |
string =~ /^thit/ | |
end | |
end | |
x.report("start_with? pass") do | |
times.times do | |
string.start_with?("this") | |
end | |
end | |
x.report("=~ pass") do | |
times.times do | |
string =~ /^this/ | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment