mirror of
https://github.com/jekyll/jekyll.git
synced 2026-01-08 22:48:00 -05:00
Compute document's relative_path faster (#6767)
Merge pull request 6767
This commit is contained in:
33
benchmark/native-vs-pathutil-relative
Executable file
33
benchmark/native-vs-pathutil-relative
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
# Benchmarking changes in https://github.com/jekyll/jekyll/pull/6767
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
|
||||||
|
require 'benchmark/ips'
|
||||||
|
require 'pathutil'
|
||||||
|
|
||||||
|
DOC_PATH = File.join(File.expand_path(__dir__), "_puppies", "rover.md")
|
||||||
|
COL_PATH = File.join(File.expand_path(__dir__), "_puppies")
|
||||||
|
|
||||||
|
|
||||||
|
def pathutil_relative
|
||||||
|
Pathutil.new(DOC_PATH).relative_path_from(COL_PATH).to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def native_relative
|
||||||
|
DOC_PATH.sub("#{COL_PATH}/", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
if pathutil_relative == native_relative
|
||||||
|
Benchmark.ips do |x|
|
||||||
|
x.report("pathutil") { pathutil_relative }
|
||||||
|
x.report("native") { native_relative }
|
||||||
|
x.compare!
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print "PATHUTIL: "
|
||||||
|
puts pathutil_relative
|
||||||
|
print "NATIVE: "
|
||||||
|
puts native_relative
|
||||||
|
end
|
||||||
@@ -83,8 +83,7 @@ module Jekyll
|
|||||||
# Returns a String path which represents the relative path from the collections_dir
|
# Returns a String path which represents the relative path from the collections_dir
|
||||||
# to this document.
|
# to this document.
|
||||||
def relative_path
|
def relative_path
|
||||||
@relative_path ||=
|
@relative_path ||= path.sub("#{site.collections_path}/", "")
|
||||||
Pathutil.new(path).relative_path_from(site.collections_path).to_s
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# The output extension of the document.
|
# The output extension of the document.
|
||||||
|
|||||||
Reference in New Issue
Block a user