Add benchmark for end_with? vs regexp
This commit is contained in:
parent
21fa47f92b
commit
4da6bfd81a
|
@ -0,0 +1,13 @@
|
||||||
|
require 'benchmark/ips'
|
||||||
|
|
||||||
|
Benchmark.ips do |x|
|
||||||
|
path_without_ending_slash = '/some/very/very/long/path/to/a/file/i/like'
|
||||||
|
x.report('no slash regexp') { path_without_ending_slash =~ /\/$/ }
|
||||||
|
x.report('no slash end_with?') { path_without_ending_slash.end_with?("/") }
|
||||||
|
end
|
||||||
|
|
||||||
|
Benchmark.ips do |x|
|
||||||
|
path_with_ending_slash = '/some/very/very/long/path/to/a/file/i/like/'
|
||||||
|
x.report('slash regexp') { path_with_ending_slash =~ /\/$/ }
|
||||||
|
x.report('slash end_with?') { path_with_ending_slash.end_with?("/") }
|
||||||
|
end
|
Loading…
Reference in New Issue