Compute document's relative_path faster (#6767)

Merge pull request 6767
This commit is contained in:
ashmaroli 2018-02-28 21:37:50 +05:30 committed by jekyllbot
parent 5748d6ac30
commit 07e49f8d23
2 changed files with 34 additions and 2 deletions

View 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

View File

@ -83,8 +83,7 @@ module Jekyll
# Returns a String path which represents the relative path from the collections_dir
# to this document.
def relative_path
@relative_path ||=
Pathutil.new(path).relative_path_from(site.collections_path).to_s
@relative_path ||= path.sub("#{site.collections_path}/", "")
end
# The output extension of the document.