Revision 68dee159c57baea40a3e936e91082a62d56c69bf authored by jekyllbot on 07 February 2018, 10:11:47 UTC, committed by jekyllbot on 07 February 2018, 10:11:47 UTC
1 parent 4c9166a
Raw File
string-replacement
#!/usr/bin/env ruby
require 'benchmark/ips'

def str
  'http://baruco.org/2014/some-talk-with-some-amount-of-value'
end

Benchmark.ips do |x|
  x.report('#tr')    { str.tr('some', 'a')    }
  x.report('#gsub')  { str.gsub('some', 'a')  }
  x.report('#gsub!') { str.gsub!('some', 'a') }
  x.report('#sub')   { str.sub('some', 'a')   }
  x.report('#sub!')  { str.sub!('some', 'a')  }
end
back to top