Skip to content

Commit

Permalink
Compute document's relative_path faster (#6767)
Browse files Browse the repository at this point in the history
Merge pull request 6767
  • Loading branch information
ashmaroli authored and jekyllbot committed Feb 28, 2018
1 parent 5748d6a commit 07e49f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 33 additions & 0 deletions benchmark/native-vs-pathutil-relative
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions lib/jekyll/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def draft?
# 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.
Expand Down

0 comments on commit 07e49f8

Please sign in to comment.