Created
December 9, 2013 21:14
-
-
Save kwleland/7880994 to your computer and use it in GitHub Desktop.
Rubinius String#scan benchmark
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' | |
require 'benchmark/ips' | |
long_text = File.new('holmes.txt').read.downcase | |
#holmes.txt @ http://norvig.com/holmes.txt | |
medium_text = long_text.slice(0,1000) | |
short_text = long_text.slice(0,100) | |
Benchmark.ips do |x| | |
x.report "string scan (long length)" do |times| | |
i = 0 | |
while i < times | |
a = long_text.scan(/[a-z]+/) | |
i += 1 | |
end | |
end | |
x.report "string scan (medium length)" do |times| | |
i = 0 | |
while i < times | |
a = medium_text.scan(/[a-z]+/) | |
i += 1 | |
end | |
end | |
x.report "string scan (short length)" do |times| | |
i = 0 | |
while i < times | |
a = short_text.scan(/[a-z]+/) | |
i += 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's a good start. I'd send that as a pull request. We can always improve it later. The "holmes.txt" would need to be committed to the repository too.