Skip to content

Instantly share code, notes, and snippets.

@durran
Created May 3, 2012 15:58
Show Gist options
  • Save durran/2586773 to your computer and use it in GitHub Desktop.
Save durran/2586773 to your computer and use it in GitHub Desktop.
require "benchmark"
Benchmark.bm do |bm|
string = "1232wrodsfds123123"
bm.report("named char") do
10000000.times do
string =~ /[:digit:]/
end
end
bm.report("old school") do
10000000.times do
string =~ /\d/
end
end
end
@durran
Copy link
Author

durran commented May 3, 2012

   user     system      total        real

named char 3.810000 0.000000 3.810000 ( 3.804518)
old school 3.650000 0.010000 3.660000 ( 3.651113)

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