Skip to content

Instantly share code, notes, and snippets.

@AnatoliiD
Last active June 6, 2016 16:53
Show Gist options
  • Save AnatoliiD/a0325121cfb580ff20478ac9813d1c15 to your computer and use it in GitHub Desktop.
Save AnatoliiD/a0325121cfb580ff20478ac9813d1c15 to your computer and use it in GitHub Desktop.
Path last slash check benchmark
require 'benchmark/ips'
true_path = '/my_mega_true_path/'
false_path = '/my_mega_false_path'
GC.disable
Benchmark.ips do |bm|
bm.report 'regexp match true' do
true_path =~ /\/$/
end
bm.report 'regexp match false' do
false_path =~ /\/$/
end
bm.report 'compare last true' do
true_path[-1] == ?/
end
bm.report 'compare last false' do
false_path[-1] == ?/
end
bm.report '#end_with? true' do
true_path.end_with?('/'.freeze)
end
bm.report '#end_with? false' do
false_path.end_with?('/'.freeze)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment