Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improved parsing #93

Open
wants to merge 266 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
266 commits
Select commit Hold shift + click to select a range
70775d2
refactor: unify terms
Spadavecchia Jul 16, 2018
032778b
refactor: cleaning code
Spadavecchia Jul 20, 2018
53f77bc
Merge pull request #63 from Spadavecchia/case-tag
basdirks Jul 25, 2018
3038df6
feat: Cycle, Include, Raw, Tablerow
Spadavecchia Jul 26, 2018
fecf799
feat: add @type annotations to describe AST
Spadavecchia Jul 27, 2018
65ab4f6
refactor: Alkmaar feedback
Spadavecchia Jul 30, 2018
f6628c9
fix: rename values -> value
Spadavecchia Jul 31, 2018
29bfd3c
refactor: cycle_group -> group, cycle_body -> body
Spadavecchia Aug 1, 2018
a1cab70
Merge pull request #66 from Spadavecchia/case-tag
Eptis Aug 1, 2018
c31d6e4
feat: Include tag
Spadavecchia Aug 1, 2018
c4f0456
Merge pull request #67 from Spadavecchia/case-tag
Eptis Aug 2, 2018
3fdf9ea
refactor: move Liquid.t() -> Liquid.NimbleParsec.t()
Spadavecchia Aug 2, 2018
380688c
Merge pull request #68 from Spadavecchia/case-tag
Eptis Aug 2, 2018
7accba3
feat: If tag
Spadavecchia Aug 2, 2018
3284d79
refactor: delete body_if tag. Use private function
Spadavecchia Aug 3, 2018
2a9ab77
Merge pull request #69 from Spadavecchia/case-tag
Eptis Aug 3, 2018
b606238
feat: Tablerow tag
Spadavecchia Aug 3, 2018
3ee606b
Merge pull request #70 from Spadavecchia/case-tag
Eptis Aug 3, 2018
fb6261c
feat: Raw tag
Spadavecchia Aug 3, 2018
7b8c22e
Merge pull request #71 from Spadavecchia/case-tag
Eptis Aug 6, 2018
3829b78
feat: Comment tag
Spadavecchia Aug 6, 2018
d859b71
fix: change Markup protocol to be Module/Function
Spadavecchia Aug 7, 2018
82fd961
fix: delete unused Markup function
Spadavecchia Aug 8, 2018
b80a462
refactor: move Markup from Combinators to Translators
Spadavecchia Aug 8, 2018
573b2fa
Merge pull request #72 from Spadavecchia/case-tag
Eptis Aug 8, 2018
e9b47ab
feat: Translate new AST to old AST
Spadavecchia Aug 9, 2018
b569202
feat: Translate new AST to old AST
Spadavecchia Aug 9, 2018
b67c629
Merge branch 'case-tag' of github.com:Spadavecchia/liquid-elixir into…
Spadavecchia Aug 9, 2018
2bbb946
test: Translators
Spadavecchia Aug 9, 2018
c873eb1
feat: Ifchanged Tag
Spadavecchia Aug 9, 2018
1e4f1b2
fix: Include.parse/1 function
Spadavecchia Aug 9, 2018
000f04b
doc(Assign): @type/@spec annotations
Spadavecchia Aug 10, 2018
c85a942
doc(Liquid.Tag): @type annotation
Spadavecchia Aug 10, 2018
8be3f64
doc(Capture): @type/@spec annotations
Spadavecchia Aug 10, 2018
b140bad
doc(Case): @type/@spec annotations
Spadavecchia Aug 10, 2018
5f72b90
refactor: delete redundant code
Spadavecchia Aug 10, 2018
22cb8c6
doc(Comment): @type/@spec annotations
Spadavecchia Aug 10, 2018
69cceab
doc(Continue): @type/@spec annotations
Spadavecchia Aug 10, 2018
f45fd2d
fix: remove warnings
Spadavecchia Aug 11, 2018
5e29822
refactor: simplified Liquid.Translators.General.not_open_if
Spadavecchia Aug 11, 2018
9da38d4
refactor: remove redundance
Spadavecchia Aug 11, 2018
a055c83
doc(Cycle): @type/@spec annotations
Spadavecchia Aug 12, 2018
6f3223f
doc(Decrement): @type/@spec annotations
Spadavecchia Aug 12, 2018
5e06be9
doc(If): @type/@spec annotations
Spadavecchia Aug 12, 2018
ef7f7b3
doc(If): @type/@spec annotations
Spadavecchia Aug 12, 2018
525149d
doc(Include): @type/@spec annotations
Spadavecchia Aug 12, 2018
74acaf4
doc(Increment): @type/@spec annotations
Spadavecchia Aug 12, 2018
7f597d1
doc(Raw): @type/@spec annotations
Spadavecchia Aug 12, 2018
286244b
doc(Tablerow): @type/@spec annotations
Spadavecchia Aug 12, 2018
b0c2bd3
doc(Unless): @type/@spec annotations
Spadavecchia Aug 12, 2018
02d627a
doc(Block): @type/@spec annotations
Spadavecchia Aug 12, 2018
1591ef2
doc(Liquid.Translators.General): @type/@spec annotations
Spadavecchia Aug 12, 2018
d327fba
refactor: use new parser into template
Spadavecchia Aug 12, 2018
a399963
test: StrictParse tests returns RuntimeError instead of SyntaxError
Spadavecchia Aug 12, 2018
ca03e99
fix: temporally comment Custom Tag tests
Spadavecchia Aug 12, 2018
a191b1c
feat(Markup): transforms AST into String
Spadavecchia Aug 12, 2018
b622756
doc(Break): @type/@spec annotations
Spadavecchia Aug 12, 2018
5d24b21
doc(LiquidVariable): @type/@spec annotations
Spadavecchia Aug 12, 2018
e5c0dbf
style: format code
Spadavecchia Aug 13, 2018
3eac147
refactor: don't use single pipe
Spadavecchia Aug 13, 2018
3270d35
style: unnecessary new line
Spadavecchia Aug 13, 2018
071ac98
refactor: rename is_else -> else?
Spadavecchia Aug 13, 2018
a1f4186
refactor: delete unnecessary function
Spadavecchia Aug 13, 2018
dd5802e
refactor: change semantic not_open_if -> conditional_statement?
Spadavecchia Aug 13, 2018
c7fef5c
refactor: use guards to simplify functions
Spadavecchia Aug 13, 2018
234ad07
refactor: function set as private
Spadavecchia Aug 13, 2018
16ba2a3
fix: delete single pipes
Spadavecchia Aug 13, 2018
358557f
refactor: improve readability
Spadavecchia Aug 13, 2018
bda35b4
fix: IsElse -> IfElse
Spadavecchia Aug 13, 2018
4df06d7
refactor: unnecessary public functions
Spadavecchia Aug 13, 2018
4444327
style: delete unnecessary new line
Spadavecchia Aug 13, 2018
a8d83a2
style: delete unnecessary new lines
Spadavecchia Aug 13, 2018
b857870
style: delete unnecessary new lines
Spadavecchia Aug 13, 2018
8ad5101
style: delete unnecessary new line
Spadavecchia Aug 13, 2018
5d2a7c1
refactor: rename badbody -> literal
Spadavecchia Aug 14, 2018
57d1c4d
style: delete unnecessary lines
Spadavecchia Aug 14, 2018
2da9704
style: delete unnecessary lines
Spadavecchia Aug 14, 2018
2e68ce2
fix: pass translate from multi process to single process
Spadavecchia Aug 14, 2018
e1cc465
doc(Translators.General): moduledoc
Spadavecchia Aug 15, 2018
8b95776
fix: delete unnecessary comments
Spadavecchia Aug 15, 2018
620d33d
refactor: rename variable t -> template
Spadavecchia Aug 15, 2018
1162d2a
doc(Case): document public functions
Spadavecchia Aug 17, 2018
8f78c39
doc(Comment): document public functions
Spadavecchia Aug 17, 2018
b945d80
doc(Cycle): document public functions
Spadavecchia Aug 17, 2018
c7bcc97
doc(Decrement): document public functions
Spadavecchia Aug 17, 2018
858584f
doc(For): document public functions
Spadavecchia Aug 17, 2018
9df4faa
doc(Generic): document public functions
Spadavecchia Aug 17, 2018
e72c5d1
doc(If): document public functions
Spadavecchia Aug 17, 2018
39c4cfc
doc(Ifchanged): document public functions
Spadavecchia Aug 17, 2018
9649d49
doc(Include): document public functions
Spadavecchia Aug 17, 2018
8e0ed35
doc(Increment): document public functions
Spadavecchia Aug 17, 2018
6d181de
doc(Raw): document public functions
Spadavecchia Aug 17, 2018
364e362
doc(Tableraw): document public functions
Spadavecchia Aug 17, 2018
1f9f248
doc: make consistent format for all documentation
Spadavecchia Aug 17, 2018
15d93f2
fix(Markup): error in literal function parsing logical operator
Spadavecchia Aug 17, 2018
6a81cc2
fix: @type annotation from empty list [] to [...]
Aug 22, 2018
4461f2a
doc(NimbleTranslator): add @type/@spec
Aug 22, 2018
074c7b9
fix: delete unnecessary pipe
Aug 22, 2018
f17455e
doc(Assign): improve documentation
Aug 22, 2018
acf1a21
doc(Capture): improve documentation
Aug 22, 2018
bc4ce05
doc(Case): improve documentation
Aug 22, 2018
f55ee3f
doc(Comment): improve documentation
Aug 22, 2018
a7335e7
doc(Capture): change documentation
Aug 22, 2018
dcce94e
doc: fix documentation
Aug 22, 2018
0cde768
doc: fix documentation
Aug 22, 2018
6272aae
doc: fix documentation
Aug 22, 2018
343eb01
doc(Cycle): improve documentation
Aug 22, 2018
7b37388
doc(Decrement): improve documentation
Aug 22, 2018
4ba77ec
doc(For): improve documentation
Aug 22, 2018
c15d5fa
doc(Generic): improve documentation
Aug 22, 2018
6c5ad08
doc(If): improve documentation
Aug 22, 2018
8cf4687
doc(IfChanged): improve documentation
Aug 22, 2018
592d8a7
doc(Include): improve documentation
Aug 22, 2018
d3c4d4a
doc(Increment): improve documentation
Aug 22, 2018
a59c048
doc(Raw): improve documentation
Aug 22, 2018
829d362
doc(Tablerow): improve documentation
Aug 22, 2018
8fb8fb3
doc(Assign): add module and public functions documentation
Aug 22, 2018
b338ca9
fix: to_string/1 -> Markup.literal/1
Aug 22, 2018
25c849d
fix: delete protocols/Markup.ex
Aug 23, 2018
5dc956e
style: apply formatter
Aug 23, 2018
74506c1
test(Markup): :parts tag
Aug 23, 2018
668ea15
test(Markup): :variable tag
Aug 23, 2018
dec8e27
case-tag test(Markup): :logical tag
Aug 23, 2018
812e1d4
case-tag test(Markup): :condition tag
Aug 23, 2018
b3e9bcb
test(Markup): :condition tag
Aug 23, 2018
eb6feb0
test(Markup): :variable_name tag
Aug 23, 2018
8455a84
test(Markup): :assignment tag
Aug 23, 2018
ded4347
test(Markup): :range tag
Aug 23, 2018
c197850
test(Markup): :reversed tag
Aug 23, 2018
e3b0717
Merge pull request #73 from Spadavecchia/case-tag
Eptis Aug 24, 2018
fceafd3
doc(Assign): add module and public functions documentation
Aug 27, 2018
c5052f4
refactor: add Render module to alias
Aug 27, 2018
e160796
doc(Case): add module and public functions documentation
Aug 27, 2018
d5d4960
refactor: delete unnecessary pipes
Aug 27, 2018
9914318
Merge pull request #74 from Spadavecchia/clean-code
Eptis Aug 27, 2018
def1fd2
feat: allow custom filters
Aug 28, 2018
45e7ccd
refactor: extract default and date to own module `Additionals`
Aug 28, 2018
998156a
refactor: extract html filters to own module HTML
Aug 28, 2018
a421f4b
refactor: extract list filters to own module List
Aug 28, 2018
d235bf0
refactor: extracts math filters to own module Math
Aug 28, 2018
81917e2
refactor: extract string filters to own module String
Aug 28, 2018
7152cd3
Merge pull request #75 from Spadavecchia/clean-code2
Eptis Aug 28, 2018
b16ae93
refactor: delete unnecessary accessors to maps and keyword
Aug 29, 2018
c0a9597
test(filters): overrides standard filters with custom filters
Aug 29, 2018
dd28e5d
refactor: mistype OverrideStandarFilter -> OverrideStandardFilter
Aug 29, 2018
126d68f
Merge pull request #82 from Spadavecchia/clean-code-filters-string
Eptis Aug 29, 2018
5ae0195
fix: remove unnecessary check empty
Aug 31, 2018
217586c
fix: remove internal recursion call to __parse__
Aug 31, 2018
c2bd4b1
fix: use recursion to call __parse__
Aug 31, 2018
0fd4af0
test: call NimbleParser instead of call each tag combinator
Aug 31, 2018
1b3f24d
chore: upgrade nimble_parser library 0.3.0 -> 0.4.0
Sep 3, 2018
cc94151
style: apply formatter
Sep 3, 2018
5cfa221
refactor: use pattern matching instead of `if`
Sep 3, 2018
7b645ad
fix: mistype mesagge -> message
Sep 3, 2018
01630dd
refactor: rename `rest` -> incorrect_markup
Sep 3, 2018
d5a9675
test: activate test
Sep 3, 2018
d8efb35
Merge pull request #83 from Spadavecchia/feature/improved-parsing
Eptis Sep 3, 2018
df23ac1
feat: Custom Tag
Sep 3, 2018
6399f88
fix: benchmark the new parser, only the parser process
Sep 3, 2018
24f7198
feat(benchmarks): run multiple scenarios
Sep 4, 2018
1da6869
fix: custom tags no longer parses the increment and decrement tag
ingsissam Sep 4, 2018
6dbb364
fix: increment tag now parses a variable in parts.
ingsissam Sep 4, 2018
1ce4378
test: add Custom Tag test
Sep 4, 2018
b4d2f19
fix: decrement tag now parses a variable in parts.
ingsissam Sep 4, 2018
2c8253e
fix: dead code
ingsissam Sep 4, 2018
f0aa0c7
Merge remote-tracking branch 'upstream/feature/improved-parsing' into…
ingsissam Sep 4, 2018
ed38af1
fix: more clear error message
ingsissam Sep 4, 2018
f5aa1d2
refeact: dead code
ingsissam Sep 4, 2018
f58a829
doc: Custom blocks
ingsissam Sep 4, 2018
04d7449
refact: to fit the new types
ingsissam Sep 4, 2018
b4c9017
Merge remote-tracking branch 'upstream/feature/multiprocess_parser' i…
fabianherrera Sep 4, 2018
8eff08c
Merge remote-tracking branch 'upstream/feature/multiprocess_parser' i…
fabianherrera Sep 5, 2018
4d3a05c
Merge pull request #97 from fabianherrera/feature/improved-parsing
Spadavecchia Sep 5, 2018
fa24a8e
consistent module doc
ingsissam Sep 5, 2018
23504b4
fix: PR requirements
ingsissam Sep 5, 2018
ea3fd46
doc: more consistent docs
ingsissam Sep 5, 2018
7346d7a
Merge pull request #95 from samunefalara80/feature/improved-parse
Spadavecchia Sep 5, 2018
f5b00de
Merge pull request #84 from Spadavecchia/feature/improved-parsing
Eptis Sep 6, 2018
6495490
chore: benchmark tag by tag
Sep 7, 2018
7415e92
Merge branch 'feature/improved-parsing' of github.com:Spadavecchia/li…
Sep 7, 2018
e530f90
refactor(Assign): clean legacy parse code
Sep 7, 2018
93df9d6
refactor(Capture): clean legacy parse code
Sep 7, 2018
1ed0452
refactor(Case): clean legacy parse code
Sep 7, 2018
74037a8
refactor(Comment): clean legacy parse code
Sep 7, 2018
359a0b7
refactor(Cycle): clean legacy parse code
Sep 7, 2018
caa01f9
refactor(Decrement): clean legacy parse code
Sep 7, 2018
04235fb
refactor(If): clean legacy parse code
Sep 7, 2018
f192f38
refactor(Increment): clean legacy parse code
Sep 7, 2018
a39e2dd
refactor(Unless): clean legacy parse code
Sep 7, 2018
84cd983
refactor: clean legacy parse code
Sep 7, 2018
f9d50d8
refactor: clean legacy code
Sep 7, 2018
0b2819a
refactor: delete Parse module from legacy parser
Sep 7, 2018
335648a
refactor: delete legacy parser code
Sep 7, 2018
6248460
fix: comented parse
ingsissam Sep 11, 2018
df9bf96
Merge pull request #98 from samunefalara80/feature/improved-parse
Spadavecchia Sep 11, 2018
9048593
Merge pull request #85 from Spadavecchia/feature/improved-parsing
Eptis Sep 11, 2018
68812ec
feat(performance): setup the scenario to new parser
Sep 20, 2018
27a7912
feat(Parser): new logic to Parser
Sep 20, 2018
1279944
doc(AST): add docs to public functions
Sep 21, 2018
0caeed6
refactor: move store_tag_in_context to Tag module
Sep 21, 2018
61c9a06
fix: use a more clean error message
Sep 21, 2018
5e3a3bd
doc: add spec annotations and more explicit docs
Sep 21, 2018
bd1087a
fix: add more validations for correct blocks opening/close
Sep 21, 2018
295ee89
feat(If): add first part of best performance If
Sep 21, 2018
c1fe6a3
feat(Tablerow): refactor to get better performance
Sep 21, 2018
0080ce6
feat: new translator
Sep 28, 2018
78af2cc
fix: delete unused code
Sep 28, 2018
bc81693
fix(Template): use new Parser
Sep 28, 2018
8c76eb2
refactor: delete dead code
Oct 1, 2018
0b91cc5
style: apply formatter with default line length (98)
Oct 2, 2018
fb05c30
doc: best description to valid_tag_name combinator
Oct 2, 2018
1bd26ca
doc(Tag): add documentation
Oct 2, 2018
a6397bc
doc: descriptive parameters
Oct 2, 2018
a81d954
doc(Tag): add documentation and spec annotation
Oct 2, 2018
2c8101a
refactor: move check end block to ast
Oct 2, 2018
2544ed1
bench: include all tags
Oct 2, 2018
eb8b24a
fix: benchmarks
Oct 3, 2018
7287312
fix: benchmark duration
Oct 3, 2018
cb3ac66
Merge pull request #86 from Spadavecchia/feature/improved-parsing
Eptis Oct 4, 2018
857eb3f
benchmark: custom tags
Oct 16, 2018
8e2c04d
refactor(General): use direct function call instead of `parsec`
Oct 21, 2018
49e84b3
refactor(General): use map instead of unnecessary traverse `to_atom`
Oct 21, 2018
4e516d9
refactor(General): delete dead code
Oct 21, 2018
9291ea7
refactor(General): reformat code
Oct 21, 2018
6727f1d
refactor(General): substitute utf8_string with utf8_char
Oct 21, 2018
b5aafc0
refactor(LexicalToken): use module attributes instead of function
Oct 21, 2018
4aaaf68
refactor(LexicalToken): use direct function call instead of `parsec`
Oct 21, 2018
1745c7d
refactor(Tag): use direct function call instead of `parsec`
Oct 21, 2018
e9a1b57
refactor(General): delete dead code
Oct 21, 2018
c16809c
refactor(Capture): use direct function call instead of `parsec`
Oct 21, 2018
98d8256
refactor(Custom): use direct function call instead of `parsec`
Oct 21, 2018
c55e41f
refactor(Cycle): use direct function call instead of `parsec`
Oct 21, 2018
4de6ee5
refactor(Decrement): use direct function call instead of `parsec`
Oct 21, 2018
6ebd7b9
refactor(EndBlock): use direct function call instead of `parsec`
Oct 21, 2018
a9f842e
refactor(For): use direct function call instead of `parsec`
Oct 21, 2018
204d9af
refactor(Include): use direct function call instead of `parsec`
Oct 21, 2018
8335025
refactor(Increment): use direct function call instead of `parsec`
Oct 21, 2018
432865f
refactor(Tablerow): use direct function call instead of `parsec`
Oct 21, 2018
fe93388
refactor(Parser): use direct function call instead of `parsec`
Oct 21, 2018
b2883df
refactor(General): use direct function call instead of `parsec`
Oct 21, 2018
95dafc7
test: move liquid variable test from LexicalTokenTest to GeneralTest
Oct 21, 2018
bc2d076
chore: benchmarks
Jan 9, 2019
387a2b6
Merge pull request #87 from Spadavecchia/feature/improved-parsing
nulian Jan 22, 2019
a584968
Merge branch 'master' into feature/improved-parsing
Jan 22, 2019
cc0a9d5
Update lock file for liquid parsing
Jan 22, 2019
5731e9a
Implement fix for elixir 1.8.0
Jan 22, 2019
c5a6037
Remove tests that got moved to other files
Jan 22, 2019
dac37f8
Add url_decode function
Jan 22, 2019
ed431e6
Bump elixir version minimum and change test script
Jan 22, 2019
0df72b8
Release it as alpha version for 1.0
Jan 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
line_length: 98
]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/bench/snapshots
erl_crash.dump
/cover
/bench/results/
/.elixir_ls
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: elixir
sudo: false
elixir:
- 1.5.1
- 1.6.6
- 1.7.4
- 1.8.0
otp_release:
Expand All @@ -10,8 +10,6 @@ otp_release:
- 21.2
matrix:
exclude:
- elixir: 1.5.1
otp_release: 21.2
- elixir: 1.8.0
otp_release: 18.3
- elixir: 1.8.0
Expand Down
36 changes: 36 additions & 0 deletions bench/full_benchmark.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Liquid.start()

path = "test/templates"
levels = ["simple", "medium", "complex"]

data =
"#{path}/db.json"
|> File.read!()
|> Poison.decode!()

levels_map =
for level <- levels,
test_case <- File.ls!("#{path}/#{level}"),
into: %{} do
markup = File.read!("#{path}/#{level}/#{test_case}/input.liquid")
parsed = Liquid.Template.parse(markup)
{level, %{test_case => %{parse: markup, render: parsed}}}
end

create_phase = fn cases, phase ->
fn ->
for {_, %{^phase => param}} <- cases do
args = if phase == :render, do: [param, data], else: [param]
apply(Liquid.Template, phase, args)
end
end
end

for phase <- [:parse] do
time = DateTime.to_string(DateTime.utc_now())
benchmark = for {level, cases} <- levels_map, into: %{} do
{"#{level} #{phase}", create_phase.(cases, phase)}
end

Benchee.run(benchmark, warmup: 5, time: 60)
end
43 changes: 43 additions & 0 deletions bench/parser_benchmark.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Liquid.start()

complex = File.read!("test/templates/complex/01/input.liquid")

middle = """
<h1>{{ product.name }}</h1>
<h2>{{ product.price }}</h2>
<h2>{{ product.price }}</h2>
{% comment %}This is a commentary{% endcomment %}
{% raw %}This is a raw tag{% endraw %}
{% for item in array %} Repeat this {% else %} Array Empty {% endfor %}
"""

simple = """
{% for item in array %} Repeat this {% else %} Array Empty {% endfor %}
"""

empty = ""

templates = [complex: complex, middle: middle, simple: simple, empty: empty]

time = DateTime.to_string(DateTime.utc_now())

Enum.each(templates,
fn {name, template} ->
IO.puts "running: #{name}"
Benchee.run(
%{
"#{name}-regex" => fn -> Liquid.Template.old_parse(template) end,
"#{name}-nimble-with-translate" => fn -> Liquid.Template.parse(template) end,
"#{name}-nimble" => fn -> Liquid.NimbleParser.parse(template) end
},
warmup: 5,
time: 60,
formatters: [
Benchee.Formatters.Console,
Benchee.Formatters.CSV
],
formatter_options: [csv: [file: "bench/results/parser-benchmarks-#{time}.csv"]]
)
end
)

44 changes: 44 additions & 0 deletions bench/parser_custom_benchmark.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Liquid.start()

defmodule Random do
def render(output, tag, context) do
{"MyCustomTag Results...output:#{output} tag:#{tag}", context}
end
end

defmodule RandomBlock do
def render(output, tag, context) do
{"MyCustomBlock Results...output:#{output} tag:#{tag}", context}
end
end


Liquid.Registers.register("random", Random, Liquid.Tag)
Liquid.Registers.register("randomblock", RandomBlock, Liquid.Block)

custom_tag = "{% random 5 %}"
custom_block = "{% randomblock 5 %} This is a Random Number: ^^^ {% endrandomblock %}"

templates = [
custom_tag: custom_tag,
custom_block: custom_block
]

benchmarks =
for {name, template} <- templates, into: %{} do
{name, fn -> Liquid.Parser.parse(template) end}
end

Benchee.run(
benchmarks,
warmup: 5,
time: 20,
print: [
benchmarking: true,
configuration: false,
fast_warning: false
],
console: [
comparison: false
]
)
69 changes: 69 additions & 0 deletions bench/parser_tags_benchmark.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Liquid.start()

complex =
"{% increment a %}{% if true %}{% decrement b %}{% if false %}{% increment c %}One{% decrement d %}{% elsif true %}Two{% else %}Three{% endif %}{% endif %}{% decrement d %}{% if false %}Four{% endif %}Last"

big_literal = File.read!("bench/templates/big_literal.liquid")
big_literal_with_tags = File.read!("bench/templates/big_literal_with_tags.liquid")
small_literal = "X"
assign = "Price in stock {% assign a = 5 %} Final Price"

capture = """
Lorem Ipsum is simply dummy text {% capture first_variable %}Hey{% endcapture %}of the printing and typesetting industry. Lorem Ipsum has {% capture first_variable %}Hey{% endcapture %}been the industry's standard dummy text ever since the {% capture first_variable %}Hey{% endcapture %}1500s, when an unknown printer {% capture first_variable %}Hey{% endcapture %}took a galley of type and scrambled it {% capture first_variable %}Hey{% endcapture %}to make a type specimen book. It has survived {% capture first_variable %}Hey{% endcapture %}not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged{% capture first_variable %}Hey{% endcapture %}. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker {% capture first_variable %}Hey{% endcapture %}including versions of Lorem Ipsum.Open{% capture first_variable %}Hey{% endcapture %}{% capture second_variable %}Hello{% endcapture %}{% capture last_variable %}{% endcapture %}CloseOpen{% capture first_variable %}Hey{% endcapture %}{% capture second_variable %}Hello{% endcapture %}{% capture last_variable %}{% endcapture %}Close
"""

small_capture = "{% capture x %}X{% endcapture %}"
case_tag = "{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}"
comment = "{% comment %} {% if true %} This is a commented block {% afi true %}{% endcomment %}"
cycle = "This time {%cycle \"one\", \"two\"%} we win MF!"
decrement = "Total Price: {% decrement a %}"
for_tag = "{%for i in array.items offset:continue limit:1000 %}{{i}}{%endfor%}"

if_tag =
"{% if false %} this text should not {% elsif true %} tests {% else %} go into the output {% endif %}"

include =
"With text {% include 'snippet', my_variable: 'apples', my_other_variable: 'oranges' %} finally!"

increment = "Price with discount: {% increment a %}"
raw = "{% raw %} {% if true %} this is a raw block {% endraw %}"
tablerow = "{% tablerow item in array %}{% endtablerow %}"

templates = [
complex: complex,
literal: big_literal,
big_literal_with_tags: big_literal_with_tags,
small_literal: small_literal,
assign: assign,
capture: capture,
small_capture: small_capture,
case: case_tag,
comment: comment,
cycle: cycle,
decrement: decrement,
for: for_tag,
if: if_tag,
include: include,
increment: increment,
raw: raw,
tablerow: tablerow
]

benchmarks =
for {name, template} <- templates, into: %{} do
{name, fn -> Liquid.Parser.parse(template) end}
end

Benchee.run(
benchmarks,
warmup: 5,
time: 20,
print: [
benchmarking: true,
configuration: false,
fast_warning: false
],
console: [
comparison: false
]
)
80 changes: 80 additions & 0 deletions bench/render_tags_benchmark.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
alias Liquid.Template

Liquid.start()

complex =
Template.parse(
"{% increment a %}{% if true %}{% decrement b %}{% if false %}{% increment c %}One{% decrement d %}{% elsif true %}Two{% else %}Three{% endif %}{% endif %}{% decrement d %}{% if false %}Four{% endif %}Last"
)

big_literal = Template.parse(File.read!("bench/templates/big_literal.liquid"))
big_literal_with_tags = Template.parse(File.read!("bench/templates/big_literal_with_tags.liquid"))
small_literal = Template.parse("X")
assign = Template.parse("Price in stock {% assign a = 5 %} Final Price")

capture =
Template.parse("""
Lorem Ipsum is simply dummy text {% capture first_variable %}Hey{% endcapture %}of the printing and typesetting industry. Lorem Ipsum has {% capture first_variable %}Hey{% endcapture %}been the industry's standard dummy text ever since the {% capture first_variable %}Hey{% endcapture %}1500s, when an unknown printer {% capture first_variable %}Hey{% endcapture %}took a galley of type and scrambled it {% capture first_variable %}Hey{% endcapture %}to make a type specimen book. It has survived {% capture first_variable %}Hey{% endcapture %}not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged{% capture first_variable %}Hey{% endcapture %}. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker {% capture first_variable %}Hey{% endcapture %}including versions of Lorem Ipsum.Open{% capture first_variable %}Hey{% endcapture %}{% capture second_variable %}Hello{% endcapture %}{% capture last_variable %}{% endcapture %}CloseOpen{% capture first_variable %}Hey{% endcapture %}{% capture second_variable %}Hello{% endcapture %}{% capture last_variable %}{% endcapture %}Close
""")

small_capture = Template.parse("{% capture x %}X{% endcapture %}")

case_tag =
Template.parse("{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}")

comment =
Template.parse(
"{% comment %} {% if true %} This is a commented block {% afi true %}{% endcomment %}"
)

cycle = Template.parse(~S(This time {%cycle "one", "two"%} we win MF!))
decrement = Template.parse("Total Price: {% decrement a %}")
for_tag = Template.parse("{%for i in array.items offset:continue limit:1000 %}{{i}}{%endfor%}")

if_tag =
Template.parse(
"{% if false %} this text should not {% elsif true %} tests {% else %} go into the output {% endif %}"
)

increment = Template.parse("Price with discount: {% increment a %}")
raw = Template.parse("{% raw %} {% if true %} this is a raw block {% endraw %}")
tablerow = Template.parse("{% tablerow item in array %}{% endtablerow %}")

templates = [
complex: complex,
literal: big_literal,
big_literal_with_tags: big_literal_with_tags,
small_literal: small_literal,
assign: assign,
capture: capture,
small_capture: small_capture,
case: case_tag,
comment: comment,
cycle: cycle,
decrement: decrement,
for: for_tag,
if: if_tag,
increment: increment,
raw: raw,
tablerow: tablerow
]

benchmarks =
for {name, template} <- templates, into: %{} do
{name, fn -> Liquid.Template.render(template) end}
end

Benchee.run(
benchmarks,
warmup: 5,
time: 20,
print: [
benchmarking: true,
configuration: false,
fast_warning: false
],
console: [
comparison: false
],
memory_time: 10
)
Loading