https://github.com/jekyll/jekyll
Raw File
Tip revision: e894f830fadbc0e9cbf7165b3005bcc543fbd59a authored by Frank Taillandier on 08 May 2020, 14:55:07 UTC
Release :gem: 3.8.7
Tip revision: e894f83
native-vs-pathutil-relative
#!/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
back to top