lbenicio-minimal-v1 1.0.3 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +471 -0
- data/_includes/analytics.html +10 -0
- data/_includes/anchor_headings.html +172 -0
- data/_includes/blog-navigation.html +18 -0
- data/_includes/conclusion.html +4 -0
- data/_includes/footer.html +13 -0
- data/_includes/fork.html +6 -0
- data/_includes/head.html +45 -0
- data/_includes/navigation.html +42 -0
- data/_includes/pagination.html +23 -0
- data/_includes/postList.html +20 -0
- data/_layouts/autopage_category.html +9 -0
- data/_layouts/autopage_collection.html +7 -0
- data/_layouts/autopage_tags.html +9 -0
- data/_layouts/default.html +28 -0
- data/_layouts/home.html +19 -0
- data/_layouts/posts.html +7 -0
- data/assets/favicon.ico +0 -0
- data/assets/monokai.scss +354 -0
- data/assets/postStyle.scss +26 -0
- data/assets/profile.jpg +0 -0
- data/assets/style.scss +143 -0
- data/assets/vendor/all.min.css +5 -0
- data/assets/webfonts/fa-brands-400.eot +0 -0
- data/assets/webfonts/fa-brands-400.svg +3717 -0
- data/assets/webfonts/fa-brands-400.ttf +0 -0
- data/assets/webfonts/fa-brands-400.woff +0 -0
- data/assets/webfonts/fa-brands-400.woff2 +0 -0
- data/assets/webfonts/fa-regular-400.eot +0 -0
- data/assets/webfonts/fa-regular-400.svg +801 -0
- data/assets/webfonts/fa-regular-400.ttf +0 -0
- data/assets/webfonts/fa-regular-400.woff +0 -0
- data/assets/webfonts/fa-regular-400.woff2 +0 -0
- data/assets/webfonts/fa-solid-900.eot +0 -0
- data/assets/webfonts/fa-solid-900.svg +5034 -0
- data/assets/webfonts/fa-solid-900.ttf +0 -0
- data/assets/webfonts/fa-solid-900.woff +0 -0
- data/assets/webfonts/fa-solid-900.woff2 +0 -0
- data/benchmark/capture-assign.rb +23 -0
- data/benchmark/conditional_liquid.rb +102 -0
- data/benchmark/end-with-vs-regexp +18 -0
- data/benchmark/file-dir-ensure-trailing-slash +56 -0
- data/benchmark/find-filter-vs-where-first-filters.rb +49 -0
- data/benchmark/flat-map +19 -0
- data/benchmark/hash-fetch +12 -0
- data/benchmark/jekyll-sanitize-path +47 -0
- data/benchmark/local-require +29 -0
- data/benchmark/native-vs-pathutil-relative +33 -0
- data/benchmark/parse-date +26 -0
- data/benchmark/parse-include-tag-params.rb +85 -0
- data/benchmark/path-manager.rb +65 -0
- data/benchmark/proc-call-vs-yield +17 -0
- data/benchmark/regexp-vs-include.rb +53 -0
- data/benchmark/sanitize-url.rb +27 -0
- data/benchmark/schwartzian_transform.rb +110 -0
- data/benchmark/sequential-assignment +15 -0
- data/benchmark/static-drop-vs-forwarded.rb +83 -0
- data/benchmark/string-concat +11 -0
- data/benchmark/string-replacement +16 -0
- data/benchmark/symbol-to-proc +9 -0
- data/rubocop/jekyll/assert_equal_literal_actual.rb +149 -0
- data/rubocop/jekyll/no_p_allowed.rb +23 -0
- data/rubocop/jekyll/no_puts_allowed.rb +23 -0
- data/rubocop/jekyll.rb +5 -0
- metadata +71 -7
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'liquid'
|
5
|
+
require 'benchmark/ips'
|
6
|
+
|
7
|
+
puts "Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
8
|
+
puts "Liquid #{Liquid::VERSION}"
|
9
|
+
|
10
|
+
template1 = '{% capture foobar %}foo{{ bar }}{% endcapture %}{{ foo }}{{ foobar }}'
|
11
|
+
template2 = '{% assign foobar = "foo" | append: bar %}{{ foobar }}'
|
12
|
+
|
13
|
+
def render(template)
|
14
|
+
Liquid::Template.parse(template).render('bar' => '42')
|
15
|
+
end
|
16
|
+
|
17
|
+
puts render(template1)
|
18
|
+
puts render(template2)
|
19
|
+
|
20
|
+
Benchmark.ips do |x|
|
21
|
+
x.report('capture') { render(template1) }
|
22
|
+
x.report('assign') { render(template2) }
|
23
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'liquid'
|
5
|
+
require 'benchmark/ips'
|
6
|
+
|
7
|
+
# Test if processing content string without any Liquid constructs, via Liquid,
|
8
|
+
# is slower than checking whether constructs exist ( using `String#include?` )
|
9
|
+
# and return-ing the "plaintext" content string as is..
|
10
|
+
#
|
11
|
+
# Ref: https://github.com/jekyll/jekyll/pull/6735
|
12
|
+
|
13
|
+
# Sample contents
|
14
|
+
WITHOUT_LIQUID = <<~TEXT
|
15
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor libero at
|
16
|
+
pharetra tempus. Etiam bibendum magna et metus fermentum, eu cursus lorem
|
17
|
+
mattis. Curabitur vel dui et lacus rutrum suscipit et eget neque.
|
18
|
+
|
19
|
+
Nullam luctus fermentum est id blandit. Phasellus consectetur ullamcorper
|
20
|
+
ligula, at finibus eros laoreet id. Etiam sit amet est in libero efficitur
|
21
|
+
tristique. Ut nec magna augue. Quisque ut fringilla lacus, ac dictum enim.
|
22
|
+
Aliquam vel ornare mauris. Suspendisse ornare diam tempor nulla facilisis
|
23
|
+
aliquet. Sed ultrices placerat ultricies.
|
24
|
+
TEXT
|
25
|
+
|
26
|
+
WITH_LIQUID = <<~LIQUID
|
27
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor libero at
|
28
|
+
pharetra tempus. {{ author }} et metus fermentum, eu cursus lorem
|
29
|
+
mattis. Curabitur vel dui et lacus rutrum suscipit et eget neque.
|
30
|
+
|
31
|
+
Nullam luctus fermentum est id blandit. Phasellus consectetur ullamcorper
|
32
|
+
ligula, {% if author == "Jane Doe" %} at finibus eros laoreet id. {% else %}
|
33
|
+
Etiam sit amet est in libero efficitur.{% endif %}
|
34
|
+
tristique. Ut nec magna augue. Quisque ut fringilla lacus, ac dictum enim.
|
35
|
+
Aliquam vel ornare mauris. Suspendisse ornare diam tempor nulla facilisis
|
36
|
+
aliquet. Sed ultrices placerat ultricies.
|
37
|
+
LIQUID
|
38
|
+
|
39
|
+
WITH_JUST_LIQUID_VAR = <<~LIQUID
|
40
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor libero at
|
41
|
+
pharetra tempus. et metus fermentum, eu cursus lorem, ac dictum enim.
|
42
|
+
mattis. Curabitur vel dui et lacus rutrum suscipit et {{ title }} neque.
|
43
|
+
|
44
|
+
Nullam luctus fermentum est id blandit. Phasellus consectetur ullamcorper
|
45
|
+
ligula, at finibus eros laoreet id. Etiam sit amet est in libero efficitur.
|
46
|
+
tristique. Ut nec magna augue. {{ author }} Quisque ut fringilla lacus
|
47
|
+
Aliquam vel ornare mauris. Suspendisse ornare diam tempor nulla facilisis
|
48
|
+
aliquet. Sed ultrices placerat ultricies.
|
49
|
+
LIQUID
|
50
|
+
|
51
|
+
SUITE = {
|
52
|
+
"plain text": WITHOUT_LIQUID,
|
53
|
+
"tags n vars": WITH_LIQUID,
|
54
|
+
"just vars": WITH_JUST_LIQUID_VAR
|
55
|
+
}.freeze
|
56
|
+
|
57
|
+
# Mimic how Jekyll's LiquidRenderer would process a non-static file, with
|
58
|
+
# some dummy payload
|
59
|
+
def always_liquid(content)
|
60
|
+
Liquid::Template.error_mode = :warn
|
61
|
+
Liquid::Template.parse(content, line_numbers: true).render(
|
62
|
+
'author' => 'John Doe',
|
63
|
+
'title' => 'FooBar'
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Mimic how the proposed change would first execute a couple of checks and
|
68
|
+
# proceed to process with Liquid if necessary
|
69
|
+
def conditional_liquid(content)
|
70
|
+
return content if content.nil? || content.empty?
|
71
|
+
return content unless content.include?('{%') || content.include?('{{')
|
72
|
+
|
73
|
+
always_liquid(content)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Test https://github.com/jekyll/jekyll/pull/6735#discussion_r165499868
|
77
|
+
# ------------------------------------------------------------------------
|
78
|
+
def check_with_regex(content)
|
79
|
+
!content.to_s.match?(/{[{%]/)
|
80
|
+
end
|
81
|
+
|
82
|
+
def check_with_builtin(content)
|
83
|
+
content.include?('{%') || content.include?('{{')
|
84
|
+
end
|
85
|
+
|
86
|
+
SUITE.each do |key, text|
|
87
|
+
Benchmark.ips do |x|
|
88
|
+
x.report("regex-check - #{key}") { check_with_regex(text) }
|
89
|
+
x.report("builtin-check - #{key}") { check_with_builtin(text) }
|
90
|
+
x.compare!
|
91
|
+
end
|
92
|
+
end
|
93
|
+
# ------------------------------------------------------------------------
|
94
|
+
|
95
|
+
# Let's roll!
|
96
|
+
SUITE.each do |key, text|
|
97
|
+
Benchmark.ips do |x|
|
98
|
+
x.report("always thru liquid - #{key}") { always_liquid(text) }
|
99
|
+
x.report("conditional liquid - #{key}") { conditional_liquid(text) }
|
100
|
+
x.compare!
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
|
6
|
+
Benchmark.ips do |x|
|
7
|
+
path_without_ending_slash = '/some/very/very/long/path/to/a/file/i/like'
|
8
|
+
x.report('no slash regexp') { path_without_ending_slash =~ %r{/$} }
|
9
|
+
x.report('no slash end_with?') { path_without_ending_slash.end_with?('/') }
|
10
|
+
x.report('no slash [-1, 1]') { path_without_ending_slash[-1, 1] == '/' }
|
11
|
+
end
|
12
|
+
|
13
|
+
Benchmark.ips do |x|
|
14
|
+
path_with_ending_slash = '/some/very/very/long/path/to/a/file/i/like/'
|
15
|
+
x.report('slash regexp') { path_with_ending_slash =~ %r{/$} }
|
16
|
+
x.report('slash end_with?') { path_with_ending_slash.end_with?('/') }
|
17
|
+
x.report('slash [-1, 1]') { path_with_ending_slash[-1, 1] == '/' }
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
|
6
|
+
# For this pull request, which changes Page#dir
|
7
|
+
# https://github.com/jekyll/jekyll/pull/4403
|
8
|
+
|
9
|
+
FORWARD_SLASH = '/'
|
10
|
+
|
11
|
+
def pre_pr(url)
|
12
|
+
url[-1, 1] == FORWARD_SLASH ? url : File.dirname(url)
|
13
|
+
end
|
14
|
+
|
15
|
+
def pr(url)
|
16
|
+
if url.end_with?(FORWARD_SLASH)
|
17
|
+
url
|
18
|
+
else
|
19
|
+
url_dir = File.dirname(url)
|
20
|
+
url_dir.end_with?(FORWARD_SLASH) ? url_dir : "#{url_dir}/"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def envygeeks(url)
|
25
|
+
return url if url.end_with?(FORWARD_SLASH) || url == FORWARD_SLASH
|
26
|
+
|
27
|
+
url = File.dirname(url)
|
28
|
+
url == FORWARD_SLASH ? url : "#{url}/"
|
29
|
+
end
|
30
|
+
|
31
|
+
# Just a slash
|
32
|
+
Benchmark.ips do |x|
|
33
|
+
path = '/'
|
34
|
+
x.report("pre_pr:#{path}") { pre_pr(path) }
|
35
|
+
x.report("pr:#{path}") { pr(path) }
|
36
|
+
x.report("envygeeks:#{path}") { pr(path) }
|
37
|
+
x.compare!
|
38
|
+
end
|
39
|
+
|
40
|
+
# No trailing slash
|
41
|
+
Benchmark.ips do |x|
|
42
|
+
path = '/some/very/very/long/path/to/a/file/i/like'
|
43
|
+
x.report("pre_pr:#{path}") { pre_pr(path) }
|
44
|
+
x.report("pr:#{path}") { pr(path) }
|
45
|
+
x.report("envygeeks:#{path}") { pr(path) }
|
46
|
+
x.compare!
|
47
|
+
end
|
48
|
+
|
49
|
+
# No trailing slash
|
50
|
+
Benchmark.ips do |x|
|
51
|
+
path = '/some/very/very/long/path/to/a/file/i/like/'
|
52
|
+
x.report("pre_pr:#{path}") { pre_pr(path) }
|
53
|
+
x.report("pr:#{path}") { pr(path) }
|
54
|
+
x.report("envygeeks:#{path}") { pr(path) }
|
55
|
+
x.compare!
|
56
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
require_relative '../lib/jekyll'
|
6
|
+
|
7
|
+
puts ''
|
8
|
+
print 'Setting up... '
|
9
|
+
|
10
|
+
SITE = Jekyll::Site.new(
|
11
|
+
Jekyll.configuration({
|
12
|
+
'source' => File.expand_path('../docs', __dir__),
|
13
|
+
'destination' => File.expand_path('../docs/_site', __dir__),
|
14
|
+
'disable_disk_cache' => true,
|
15
|
+
'quiet' => true
|
16
|
+
})
|
17
|
+
)
|
18
|
+
|
19
|
+
TEMPLATE_1 = Liquid::Template.parse(<<~HTML)
|
20
|
+
{%- assign doc = site.documents | where: 'url', '/docs/assets/' | first -%}
|
21
|
+
{{- doc.title -}}
|
22
|
+
HTML
|
23
|
+
|
24
|
+
TEMPLATE_2 = Liquid::Template.parse(<<~HTML)
|
25
|
+
{%- assign doc = site.documents | find: 'url', '/docs/assets/' -%}
|
26
|
+
{{- doc.title -}}
|
27
|
+
HTML
|
28
|
+
|
29
|
+
%i[reset read generate].each { |phase| SITE.send(phase) }
|
30
|
+
|
31
|
+
puts 'done.'
|
32
|
+
puts 'Testing... '
|
33
|
+
puts " #{'where + first'.cyan} results in #{TEMPLATE_1.render(SITE.site_payload).inspect.green}"
|
34
|
+
puts " #{'find'.cyan} results in #{TEMPLATE_2.render(SITE.site_payload).inspect.green}"
|
35
|
+
|
36
|
+
if TEMPLATE_1.render(SITE.site_payload) == TEMPLATE_2.render(SITE.site_payload)
|
37
|
+
puts 'Success! Proceeding to run benchmarks.'.green
|
38
|
+
puts ''
|
39
|
+
else
|
40
|
+
puts 'Something went wrong. Aborting.'.magenta
|
41
|
+
puts ''
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
45
|
+
Benchmark.ips do |x|
|
46
|
+
x.report('where + first') { TEMPLATE_1.render(SITE.site_payload) }
|
47
|
+
x.report('find') { TEMPLATE_2.render(SITE.site_payload) }
|
48
|
+
x.compare!
|
49
|
+
end
|
data/benchmark/flat-map
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
|
6
|
+
enum = (0..50).to_a
|
7
|
+
nested = enum.map { |i| [i] }
|
8
|
+
|
9
|
+
def do_thing(blah)
|
10
|
+
blah * 1
|
11
|
+
end
|
12
|
+
|
13
|
+
Benchmark.ips do |x|
|
14
|
+
x.report('.map.flatten with nested arrays') { nested.map { |i| do_thing(i) }.flatten(1) }
|
15
|
+
x.report('.flat_map with nested arrays') { nested.flat_map { |i| do_thing(i) } }
|
16
|
+
|
17
|
+
x.report('.map.flatten with no nested arrays') { enum.map { |i| do_thing(i) }.flatten(1) }
|
18
|
+
x.report('.flat_map with no nested arrays') { enum.flat_map { |i| do_thing(i) } }
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
|
6
|
+
h = { bar: 'uco' }
|
7
|
+
|
8
|
+
Benchmark.ips do |x|
|
9
|
+
x.report('fetch with no block') { h.fetch(:bar, (0..9).to_a) }
|
10
|
+
x.report('fetch with a block') { h.fetch(:bar) { (0..9).to_a } }
|
11
|
+
x.report('brackets with an ||') { h[:bar] || (0..9).to_a }
|
12
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/jekyll'
|
5
|
+
require 'benchmark/ips'
|
6
|
+
|
7
|
+
base_directory = Dir.pwd
|
8
|
+
|
9
|
+
Benchmark.ips do |x|
|
10
|
+
#
|
11
|
+
# Does not include the base_directory
|
12
|
+
#
|
13
|
+
x.report('with no questionable path') do
|
14
|
+
Jekyll.sanitized_path(base_directory, '')
|
15
|
+
end
|
16
|
+
x.report('with a single-part questionable path') do
|
17
|
+
Jekyll.sanitized_path(base_directory, 'thingy')
|
18
|
+
end
|
19
|
+
x.report('with a multi-part questionable path') do
|
20
|
+
Jekyll.sanitized_path(base_directory, 'thingy/in/my/soup')
|
21
|
+
end
|
22
|
+
x.report('with a single-part traversal path') do
|
23
|
+
Jekyll.sanitized_path(base_directory, '../thingy')
|
24
|
+
end
|
25
|
+
x.report('with a multi-part traversal path') do
|
26
|
+
Jekyll.sanitized_path(base_directory, '../thingy/in/my/../../soup')
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Including the base_directory
|
31
|
+
#
|
32
|
+
x.report('with the exact same paths') do
|
33
|
+
Jekyll.sanitized_path(base_directory, base_directory)
|
34
|
+
end
|
35
|
+
x.report('with a single-part absolute path including the base_directory') do
|
36
|
+
Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy'))
|
37
|
+
end
|
38
|
+
x.report('with a multi-part absolute path including the base_directory') do
|
39
|
+
Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy/in/my/soup'))
|
40
|
+
end
|
41
|
+
x.report('with a single-part traversal path including the base_directory') do
|
42
|
+
Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy/..'))
|
43
|
+
end
|
44
|
+
x.report('with a multi-part traversal path including the base_directory') do
|
45
|
+
Jekyll.sanitized_path(base_directory, File.join('thingy/in/my/../../soup'))
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
require 'jekyll'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
DATA = { 'foo' => 'bar', 'alpha' => { 'beta' => 'gamma' }, 'lipsum' => %w[lorem ipsum dolor] }.freeze
|
9
|
+
|
10
|
+
def local_require
|
11
|
+
require 'json'
|
12
|
+
JSON.pretty_generate(DATA)
|
13
|
+
end
|
14
|
+
|
15
|
+
def global_require
|
16
|
+
JSON.pretty_generate(DATA)
|
17
|
+
end
|
18
|
+
|
19
|
+
def graceful_require
|
20
|
+
Jekyll::External.require_with_graceful_fail('json')
|
21
|
+
JSON.pretty_generate(DATA)
|
22
|
+
end
|
23
|
+
|
24
|
+
Benchmark.ips do |x|
|
25
|
+
x.report('local-require') { local_require }
|
26
|
+
x.report('global-require') { global_require }
|
27
|
+
x.report('graceful-require') { graceful_require }
|
28
|
+
x.compare!
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# -------------------------------------------------------------------
|
5
|
+
# Benchmarking changes in https://github.com/jekyll/jekyll/pull/6767
|
6
|
+
# -------------------------------------------------------------------
|
7
|
+
|
8
|
+
require 'benchmark/ips'
|
9
|
+
require 'pathutil'
|
10
|
+
|
11
|
+
DOC_PATH = File.join(File.expand_path(__dir__), '_puppies', 'rover.md')
|
12
|
+
COL_PATH = File.join(File.expand_path(__dir__), '_puppies')
|
13
|
+
|
14
|
+
def pathutil_relative
|
15
|
+
Pathutil.new(DOC_PATH).relative_path_from(COL_PATH).to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def native_relative
|
19
|
+
DOC_PATH.sub("#{COL_PATH}/", '')
|
20
|
+
end
|
21
|
+
|
22
|
+
if pathutil_relative == native_relative
|
23
|
+
Benchmark.ips do |x|
|
24
|
+
x.report('pathutil') { pathutil_relative }
|
25
|
+
x.report('native') { native_relative }
|
26
|
+
x.compare!
|
27
|
+
end
|
28
|
+
else
|
29
|
+
print 'PATHUTIL: '
|
30
|
+
puts pathutil_relative
|
31
|
+
print 'NATIVE: '
|
32
|
+
puts native_relative
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../lib/jekyll'
|
5
|
+
require 'benchmark/ips'
|
6
|
+
|
7
|
+
date = '2014-08-02 14:43:06 PDT'
|
8
|
+
time = Time.parse(date)
|
9
|
+
|
10
|
+
Benchmark.ips do |x|
|
11
|
+
x.report('Time.parse') do
|
12
|
+
Time.parse(date)
|
13
|
+
end
|
14
|
+
|
15
|
+
x.report('localtime') do
|
16
|
+
Time.parse(date).localtime
|
17
|
+
end
|
18
|
+
|
19
|
+
x.report('localtime parsed') do
|
20
|
+
time.localtime
|
21
|
+
end
|
22
|
+
|
23
|
+
x.report('Utils.parse_date') do
|
24
|
+
Jekyll::Utils.parse_date(date)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# For pull request: https://github.com/jekyll/jekyll/pull/8192
|
5
|
+
|
6
|
+
require 'benchmark/ips'
|
7
|
+
require 'bundler/setup'
|
8
|
+
require 'memory_profiler'
|
9
|
+
require 'jekyll'
|
10
|
+
|
11
|
+
CONTEXT = { 'bar' => 'The quick brown fox' }.freeze
|
12
|
+
MARKUP_1 = %(foo=bar lorem="ipsum \\"dolor\\"" alpha='beta \\'gamma\\'')
|
13
|
+
MARKUP_2 = %(foo=bar lorem="ipsum 'dolor'" alpha='beta "gamma"')
|
14
|
+
|
15
|
+
def old_parse_params(markup)
|
16
|
+
params = {}
|
17
|
+
|
18
|
+
while (match = Jekyll::Tags::IncludeTag::VALID_SYNTAX.match(markup))
|
19
|
+
markup = markup[match.end(0)..]
|
20
|
+
|
21
|
+
value = if match[2]
|
22
|
+
match[2].gsub('\\"', '"')
|
23
|
+
elsif match[3]
|
24
|
+
match[3].gsub("\\'", "'")
|
25
|
+
elsif match[4]
|
26
|
+
CONTEXT[match[4]]
|
27
|
+
end
|
28
|
+
|
29
|
+
params[match[1]] = value
|
30
|
+
end
|
31
|
+
params
|
32
|
+
end
|
33
|
+
|
34
|
+
def new_parse_params(markup)
|
35
|
+
params = {}
|
36
|
+
markup.scan(Jekyll::Tags::IncludeTag::VALID_SYNTAX) do |key, d_quoted, s_quoted, variable|
|
37
|
+
value = if d_quoted
|
38
|
+
d_quoted.include?('\\"') ? d_quoted.gsub('\\"', '"') : d_quoted
|
39
|
+
elsif s_quoted
|
40
|
+
s_quoted.include?("\\'") ? s_quoted.gsub("\\'", "'") : s_quoted
|
41
|
+
elsif variable
|
42
|
+
CONTEXT[variable]
|
43
|
+
end
|
44
|
+
|
45
|
+
params[key] = value
|
46
|
+
end
|
47
|
+
params
|
48
|
+
end
|
49
|
+
|
50
|
+
def report(label, markup, color, &block)
|
51
|
+
prof_report = MemoryProfiler.report(&block)
|
52
|
+
|
53
|
+
allocated_memory = prof_report.scale_bytes(prof_report.total_allocated_memsize)
|
54
|
+
allocated_objects = prof_report.total_allocated
|
55
|
+
retained_memory = prof_report.scale_bytes(prof_report.total_retained_memsize)
|
56
|
+
retained_objects = prof_report.total_retained
|
57
|
+
|
58
|
+
puts <<~MSG.send(color)
|
59
|
+
#{"#{label} ".ljust(49, '-')}
|
60
|
+
|
61
|
+
MARKUP: #{markup}
|
62
|
+
RESULT: #{yield}
|
63
|
+
|
64
|
+
Total allocated: #{allocated_memory} (#{allocated_objects} objects)
|
65
|
+
Total retained: #{retained_memory} (#{retained_objects} objects)
|
66
|
+
MSG
|
67
|
+
end
|
68
|
+
|
69
|
+
report('old w/ escaping', MARKUP_1, :magenta) { old_parse_params(MARKUP_1) }
|
70
|
+
report('new w/ escaping', MARKUP_1, :cyan) { new_parse_params(MARKUP_1) }
|
71
|
+
|
72
|
+
report('old no escaping', MARKUP_2, :green) { old_parse_params(MARKUP_2) }
|
73
|
+
report('new no escaping', MARKUP_2, :yellow) { new_parse_params(MARKUP_2) }
|
74
|
+
|
75
|
+
Benchmark.ips do |x|
|
76
|
+
x.report('old + esc'.magenta) { old_parse_params(MARKUP_1) }
|
77
|
+
x.report('new + esc'.cyan) { new_parse_params(MARKUP_1) }
|
78
|
+
x.compare!
|
79
|
+
end
|
80
|
+
|
81
|
+
Benchmark.ips do |x|
|
82
|
+
x.report('old - esc'.green) { old_parse_params(MARKUP_2) }
|
83
|
+
x.report('new - esc'.yellow) { new_parse_params(MARKUP_2) }
|
84
|
+
x.compare!
|
85
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'benchmark/ips'
|
4
|
+
require 'jekyll'
|
5
|
+
|
6
|
+
class FooPage
|
7
|
+
def initialize(dir:, name:)
|
8
|
+
@dir = dir
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def slow_path
|
13
|
+
File.join(*[@dir, @name].map(&:to_s).reject(&:empty?)).sub(%r{\A/}, '')
|
14
|
+
end
|
15
|
+
|
16
|
+
def fast_path
|
17
|
+
Jekyll::PathManager.join(@dir, @name).sub(%r{\A/}, '')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
nil_page = FooPage.new(dir: nil, name: nil)
|
22
|
+
empty_page = FooPage.new(dir: '', name: '')
|
23
|
+
root_page = FooPage.new(dir: '', name: 'ipsum.md')
|
24
|
+
nested_page = FooPage.new(dir: 'lorem', name: 'ipsum.md')
|
25
|
+
slashed_page = FooPage.new(dir: '/lorem/', name: '/ipsum.md')
|
26
|
+
|
27
|
+
if nil_page.slow_path == nil_page.fast_path
|
28
|
+
Benchmark.ips do |x|
|
29
|
+
x.report('nil_page slow') { nil_page.slow_path }
|
30
|
+
x.report('nil_page fast') { nil_page.fast_path }
|
31
|
+
x.compare!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if empty_page.slow_path == empty_page.fast_path
|
36
|
+
Benchmark.ips do |x|
|
37
|
+
x.report('empty_page slow') { empty_page.slow_path }
|
38
|
+
x.report('empty_page fast') { empty_page.fast_path }
|
39
|
+
x.compare!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
if root_page.slow_path == root_page.fast_path
|
44
|
+
Benchmark.ips do |x|
|
45
|
+
x.report('root_page slow') { root_page.slow_path }
|
46
|
+
x.report('root_page fast') { root_page.fast_path }
|
47
|
+
x.compare!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
if nested_page.slow_path == nested_page.fast_path
|
52
|
+
Benchmark.ips do |x|
|
53
|
+
x.report('nested_page slow') { nested_page.slow_path }
|
54
|
+
x.report('nested_page fast') { nested_page.fast_path }
|
55
|
+
x.compare!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
if slashed_page.slow_path == slashed_page.fast_path
|
60
|
+
Benchmark.ips do |x|
|
61
|
+
x.report('slashed_page slow') { slashed_page.slow_path }
|
62
|
+
x.report('slashed_page fast') { slashed_page.fast_path }
|
63
|
+
x.compare!
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
|
6
|
+
def fast
|
7
|
+
yield
|
8
|
+
end
|
9
|
+
|
10
|
+
def slow(&block)
|
11
|
+
block.call
|
12
|
+
end
|
13
|
+
|
14
|
+
Benchmark.ips do |x|
|
15
|
+
x.report('yield') { fast { (0..9).to_a } }
|
16
|
+
x.report('block.call') { slow { (0..9).to_a } }
|
17
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
|
6
|
+
# For this pull request, which changes Page#dir
|
7
|
+
# https://github.com/jekyll/jekyll/pull/4403
|
8
|
+
|
9
|
+
CONTENT_CONTAINING = <<~HTML
|
10
|
+
<!DOCTYPE HTML>
|
11
|
+
<html lang="en-US">
|
12
|
+
<head>
|
13
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
14
|
+
<meta charset="UTF-8">
|
15
|
+
<title>Jemoji</title>
|
16
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
17
|
+
<link rel="stylesheet" href="/css/screen.css">
|
18
|
+
</head>
|
19
|
+
<body class="wrap">
|
20
|
+
<p><img class="emoji" title=":+1:" alt=":+1:" src="https://assets.github.com/images/icons/emoji/unicode/1f44d.png" height="20" width="20" align="absmiddle"></p>
|
21
|
+
|
22
|
+
</body>
|
23
|
+
</html>
|
24
|
+
HTML
|
25
|
+
CONTENT_NOT_CONTAINING = <<~HTML
|
26
|
+
<!DOCTYPE HTML>
|
27
|
+
<html lang="en-US">
|
28
|
+
<head>
|
29
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
30
|
+
<meta charset="UTF-8">
|
31
|
+
<title>Jemoji</title>
|
32
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
33
|
+
<link rel="stylesheet" href="/css/screen.css">
|
34
|
+
</head>
|
35
|
+
<body class="wrap">
|
36
|
+
<p><img class="emoji" title=":+1:" alt=":+1:" src="https://assets.github.com/images/icons/emoji/unicode/1f44d.png" height="20" width="20" align="absmiddle"></p>
|
37
|
+
|
38
|
+
</body>
|
39
|
+
</html>
|
40
|
+
HTML
|
41
|
+
|
42
|
+
Benchmark.ips do |x|
|
43
|
+
x.report('no body include?') { CONTENT_NOT_CONTAINING.include?('<body') }
|
44
|
+
x.report('no body regexp') { CONTENT_NOT_CONTAINING =~ /<\s*body/ }
|
45
|
+
x.compare!
|
46
|
+
end
|
47
|
+
|
48
|
+
# No trailing slash
|
49
|
+
Benchmark.ips do |x|
|
50
|
+
x.report('with body include?') { CONTENT_CONTAINING.include?('<body') }
|
51
|
+
x.report('with body regexp') { CONTENT_CONTAINING =~ /<\s*body/ }
|
52
|
+
x.compare!
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'benchmark/ips'
|
5
|
+
|
6
|
+
PATH = '/../../..../...//.....//lorem/ipsum//dolor///sit.xyz'
|
7
|
+
|
8
|
+
def sanitize_with_regex
|
9
|
+
"/#{PATH.gsub(%r!/{2,}!, '/').gsub(%r{\.+/|\A/+}, '')}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def sanitize_with_builtin
|
13
|
+
"/#{PATH}".gsub('..', '/').gsub('./', '').squeeze('/')
|
14
|
+
end
|
15
|
+
|
16
|
+
if sanitize_with_regex == sanitize_with_builtin
|
17
|
+
Benchmark.ips do |x|
|
18
|
+
x.report('sanitize w/ regexes') { sanitize_with_regex }
|
19
|
+
x.report('sanitize w/ builtin') { sanitize_with_builtin }
|
20
|
+
x.compare!
|
21
|
+
end
|
22
|
+
else
|
23
|
+
puts "w/ regexes: #{sanitize_with_regex}"
|
24
|
+
puts "w/ builtin: #{sanitize_with_builtin}"
|
25
|
+
puts ''
|
26
|
+
puts 'Thank you. Do try again :('
|
27
|
+
end
|