Skip to content

Instantly share code, notes, and snippets.

@iorionda
Created March 5, 2013 09:18
Show Gist options
  • Select an option

  • Save iorionda/5089005 to your computer and use it in GitHub Desktop.

Select an option

Save iorionda/5089005 to your computer and use it in GitHub Desktop.
# -*- coding:utf-8 -*-
require 'benchmark'
def gsub_check
10000.times do |n|
" ".gsub(/ /, " ")
end
end
def gsub_check_2
10000.times do |n|
" ".gsub!(/ /, " ")
end
end
def tr_check
10000.times do |n|
" ".tr(" ", " ")
end
end
Benchmark.bm(100) do |x|
x.report("gsub") { gsub_check }
x.report("gsub!") { gsub_check_2 }
x.report("tr") { tr_check }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment