Skip to content

Instantly share code, notes, and snippets.

@kwleland
Created December 9, 2013 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwleland/7880994 to your computer and use it in GitHub Desktop.
Save kwleland/7880994 to your computer and use it in GitHub Desktop.
Rubinius String#scan benchmark
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
@chuckremes
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment