-
-
Save seth/608668 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
$ ./start_with_and_index.rb | |
user system total real | |
index fail 0.420000 0.000000 0.420000 ( 0.424444) | |
start_with? fail 0.990000 0.000000 0.990000 ( 0.993577) | |
index pass 0.420000 0.000000 0.420000 ( 0.424240) | |
start_with? pass 1.650000 0.020000 1.670000 ( 1.672174) |
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
#!/usr/bin/env ruby | |
require 'benchmark' | |
times = 1000000 | |
string = "this is a string" | |
Benchmark.bm(16) do |x| | |
x.report("index fail") do | |
times.times do | |
string.index("this is a stripe") | |
end | |
end | |
x.report("start_with? fail") do | |
times.times do | |
string.start_with?("this is a stripe") | |
end | |
end | |
#### | |
x.report("index pass") do | |
times.times do | |
string.index("this is a string") | |
end | |
end | |
x.report("start_with? pass") do | |
times.times do | |
string.start_with?("this is a string") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment