Skip to content

Instantly share code, notes, and snippets.

@tamalw
Created January 22, 2014 23:01
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 tamalw/8569226 to your computer and use it in GitHub Desktop.
Save tamalw/8569226 to your computer and use it in GitHub Desktop.
require 'benchmark'
Benchmark.bm do |b|
b.report "upcase " do
e = "Collaboratively administrate empowered markets via plug-and-play networks -- http://www.cipsum.com/"
1_000_000.times { e[0] == e[0].upcase }
end
b.report " /^[A-Z]/ " do
e = "Collaboratively administrate empowered markets via plug-and-play networks -- http://www.cipsum.com/"
1_000_000.times { e =~ /^[A-Z]/ }
end
b.report "include? " do
e = "Collaboratively administrate empowered markets via plug-and-play networks -- http://www.cipsum.com/"
1_000_000.times { ("A".."Z").include?(e.chr) }
end
b.report " /^[[:upper:]]/" do
e = "Collaboratively administrate empowered markets via plug-and-play networks -- http://www.cipsum.com/"
1_000_000.times { e =~ /^[[:upper:]]/ }
end
b.report "ord " do
e = "Collaboratively administrate empowered markets via plug-and-play networks -- http://www.cipsum.com/"
1_000_000.times { i = e.ord; i > 64 && i < 91 }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment