Skip to content

Instantly share code, notes, and snippets.

@ecylmz
Created September 29, 2014 13:44
Show Gist options
  • Save ecylmz/f2b9ae72ad363c9ac4d4 to your computer and use it in GitHub Desktop.
Save ecylmz/f2b9ae72ad363c9ac4d4 to your computer and use it in GitHub Desktop.
# encoding: utf-8
require 'benchmark'
str = ' Emre Can Yılmaz '
squeeze_result = Benchmark.measure do
1.upto(1_000_000) { str.squeeze(' ').strip }
end
gsub_result = Benchmark.measure do
1.upto(1_000_000) { str.gsub('/\s+/', ' ').strip }
end
p squeeze_result.to_s
p gsub_result.to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment