Skip to content

Instantly share code, notes, and snippets.

@selman
Created April 13, 2012 14:11
Show Gist options
  • Save selman/2377149 to your computer and use it in GitHub Desktop.
Save selman/2377149 to your computer and use it in GitHub Desktop.
require 'benchmark'
Benchmark.bmbm(10) do |x|
x.report("noregexp") {
"content-management-systems".split("-").map(&:capitalize).join(" ").
split(" ").map(&:downcase).join("-")
}
x.report("rgexp") {
"content-management-systems".
gsub(/(\w+)(-)?/) { ($2 ? $1 + " " : $1).capitalize! }.
gsub(/(\w+)(\s)?/) { ($2 ? $1 + "-" : $1).downcase! }
}
end
__END__
Rehearsal ----------------------------------------------
noregexp 0.000000 0.000000 0.000000 ( 0.000032)
rgexp 0.000000 0.000000 0.000000 ( 0.000035)
------------------------------------- total: 0.000000sec
user system total real
noregexp 0.000000 0.000000 0.000000 ( 0.000051)
rgexp 0.000000 0.000000 0.000000 ( 0.000058)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment