Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (19 sloc) 619 Bytes
require 'benchmark/ips'
URL = 'http://www.thelongestlistofthelongeststuffatthelongestdomainnameatlonglast.com/wearejustdoingthistobestupidnowsincethiscangoonforeverandeverandeverbutitstilllookskindaneatinthebrowsereventhoughitsabigwasteoftimeandenergyandhasnorealpointbutwehadtodoitanyways.html'
def slow
URL.gsub('http://', 'https://')
end
def fast
URL.sub('http://', 'https://')
end
def fastest
str = URL.dup
str['http://'] = 'https://'
str
end
Benchmark.ips do |x|
x.report('String#gsub') { slow }
x.report('String#sub') { fast }
x.report('String#dup["string"]=') { fastest }
x.compare!
end
You can’t perform that action at this time.