Last active
June 6, 2016 16:53
-
-
Save AnatoliiD/a0325121cfb580ff20478ac9813d1c15 to your computer and use it in GitHub Desktop.
Path last slash check benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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