Skip to content

Instantly share code, notes, and snippets.

@sashaegorov
Forked from tbuehlmann/string_sub_bm.rb
Created September 8, 2015 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sashaegorov/d9a05b63b47878f583cf to your computer and use it in GitHub Desktop.
Save sashaegorov/d9a05b63b47878f583cf to your computer and use it in GitHub Desktop.
require 'benchmark'
N = 10_000_000
Benchmark.bmbm do |bm|
bm.report('String') do
N.times do
a = 'devise/session'
a.sub('/', '-')
end
end
bm.report('Regexp') do
N.times do
a = 'devise/session'
a.sub(/\//, '-')
end
end
bm.report('tr') do
N.times do
a = 'devise/session'
a.tr('/', '-')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment