Skip to content

Instantly share code, notes, and snippets.

@amatsuda
Created November 12, 2011 15:11
Show Gist options
  • Select an option

  • Save amatsuda/1360650 to your computer and use it in GitHub Desktop.

Select an option

Save amatsuda/1360650 to your computer and use it in GitHub Desktop.
String#gsub: String vs Regexp
ruby-1.9.3-p0> Benchmark.ms { 100000.times { 'a-b-c-d-e'.gsub /-/, '_' } }
=> 422.281
ruby-1.9.3-p0> Benchmark.ms { 100000.times { 'a-b-c-d-e'.gsub '-', '_' } }
=> 471.096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment