Sha256: 87093d324b4dd5a5e00f54ed383c6e47e002f8fcb9e9a1e142e5a9b4f18d365e

Contents?: true

Size: 1.28 KB

Versions: 26

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'benchmark/ips'

# For this pull request, which changes Page#dir
# https://github.com/jekyll/jekyll/pull/4403

FORWARD_SLASH = '/'

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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
lbenicio-minimal-v1-1.6.4 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.6.3 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.6.2 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.6.1 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.5.3 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.5.2 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.5.0 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.4.0 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.3.3 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.3.2 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.3.1 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.3.0 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.2.1 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.2.0 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.1.9 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.1.8 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.1.7 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.1.6 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.1.5 benchmark/file-dir-ensure-trailing-slash
lbenicio-minimal-v1-1.1.4 benchmark/file-dir-ensure-trailing-slash