Created
March 9, 2015 01:30
-
-
Save bradland/5bfabe4fea408dd2cbd8 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/ips' | |
TEST_STRING = "FooBar" * 10 | |
Benchmark.ips do |x| | |
x.report("count") do | |
TEST_STRING.count('[A-Z]') | |
end | |
x.report("gsub") do | |
TEST_STRING.gsub(/[^A-Z]/, "").length | |
end | |
x.report("scan") do | |
TEST_STRING.scan(/[A-Z]/).size | |
end | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results (iMac 3.5 GHz i7):