Just some string benchmark

Been thinking how #delete #tr #gsub methods are fast:

'some@email.com'.delete('@.')
'some@email.com'.tr('@.', '')
'some@email.com'.gsub('@', '').gsub('.', '')

Result

method real
#delete (0.008266)
#tr (0.009554)
#gsub (0.026041)

The results will be different on other machine but it looks like #delete is fastest.

Code used for benchmark

require 'benchmark'

Benchmark.bmbm do |x|
   x.report { 10000.times { 'donat@gmail.com'.delete('@.') } }
   x.report { 10000.times { 'donat@gmail.com'.tr('@.', '') } }
   x.report { 10000.times { 'donat@gmail.com'.gsub('@', '').gsub('.', '') } }
end