Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
20 lines (15 sloc) 317 Bytes
require "benchmark/ips"
if RUBY_VERSION >= '2.5.0'
STRING = 'Foo::Foo::Bar'.freeze
def fast
STRING.delete_prefix('Foo::')
end
def slow
STRING.sub(/\AFoo::/, '')
end
Benchmark.ips do |x|
x.report("String#delete_prefix") { fast }
x.report('String#sub') { slow }
x.compare!
end
end
You can’t perform that action at this time.