Add benchmarks for Page#dir
This commit is contained in:
parent
38b64faeb2
commit
b70ee10198
|
@ -4,10 +4,12 @@ Benchmark.ips do |x|
|
||||||
path_without_ending_slash = '/some/very/very/long/path/to/a/file/i/like'
|
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 regexp') { path_without_ending_slash =~ /\/$/ }
|
||||||
x.report('no slash end_with?') { path_without_ending_slash.end_with?("/") }
|
x.report('no slash end_with?') { path_without_ending_slash.end_with?("/") }
|
||||||
|
x.report('no slash [-1, 1]') { path_without_ending_slash[-1, 1] == "/" }
|
||||||
end
|
end
|
||||||
|
|
||||||
Benchmark.ips do |x|
|
Benchmark.ips do |x|
|
||||||
path_with_ending_slash = '/some/very/very/long/path/to/a/file/i/like/'
|
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 regexp') { path_with_ending_slash =~ /\/$/ }
|
||||||
x.report('slash end_with?') { path_with_ending_slash.end_with?("/") }
|
x.report('slash end_with?') { path_with_ending_slash.end_with?("/") }
|
||||||
|
x.report('slash [-1, 1]') { path_with_ending_slash[-1, 1] == "/" }
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
require 'benchmark/ips'
|
||||||
|
|
||||||
|
# For this pull request, which changes Page#dir
|
||||||
|
# https://github.com/jekyll/jekyll/pull/4403
|
||||||
|
|
||||||
|
FORWARD_SLASH = '/'.freeze
|
||||||
|
|
||||||
|
def pre_pr(url)
|
||||||
|
url[-1, 1] == FORWARD_SLASH ? url : File.dirname(url)
|
||||||
|
end
|
||||||
|
|
||||||
|
def pr(url)
|
||||||
|
if url.end_with?(FORWARD_SLASH)
|
||||||
|
url
|
||||||
|
else
|
||||||
|
url_dir = File.dirname(url)
|
||||||
|
url_dir.end_with?(FORWARD_SLASH) ? url_dir : "#{url_dir}/"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def envygeeks(url)
|
||||||
|
return url if url.end_with?(FORWARD_SLASH) || url == FORWARD_SLASH
|
||||||
|
|
||||||
|
url = File.dirname(url)
|
||||||
|
url == FORWARD_SLASH ? url : "#{url}/"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Just a slash
|
||||||
|
Benchmark.ips do |x|
|
||||||
|
path = '/'
|
||||||
|
x.report("pre_pr:#{path}") { pre_pr(path) }
|
||||||
|
x.report("pr:#{path}") { pr(path) }
|
||||||
|
x.report("envygeeks:#{path}") { pr(path) }
|
||||||
|
x.compare!
|
||||||
|
end
|
||||||
|
|
||||||
|
# No trailing slash
|
||||||
|
Benchmark.ips do |x|
|
||||||
|
path = '/some/very/very/long/path/to/a/file/i/like'
|
||||||
|
x.report("pre_pr:#{path}") { pre_pr(path) }
|
||||||
|
x.report("pr:#{path}") { pr(path) }
|
||||||
|
x.report("envygeeks:#{path}") { pr(path) }
|
||||||
|
x.compare!
|
||||||
|
end
|
||||||
|
|
||||||
|
# No trailing slash
|
||||||
|
Benchmark.ips do |x|
|
||||||
|
path = '/some/very/very/long/path/to/a/file/i/like/'
|
||||||
|
x.report("pre_pr:#{path}") { pre_pr(path) }
|
||||||
|
x.report("pr:#{path}") { pr(path) }
|
||||||
|
x.report("envygeeks:#{path}") { pr(path) }
|
||||||
|
x.compare!
|
||||||
|
end
|
Loading…
Reference in New Issue