Created
August 11, 2013 18:31
-
-
Save arr-ee/6206241 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
chars = 'abcdeABCDE!@#$%1234 ' | |
res_str = '' | |
n = 1000 | |
100_000.times do | |
res_str << chars[rand(chars.length)] | |
end | |
Benchmark.bm(15) do |x| | |
x.report('map downcase'){n.times{res_str.scan(/\w/).map(&:downcase)}} | |
x.report('scan downcase'){n.times{res_str.scan(/\w/){|w| w.downcase}}} | |
x.report('one downcase'){n.times{res_str.downcase.scan(/\w/)}} | |
end |
Author
arr-ee
commented
Aug 11, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment