Or see the list of project sponsors.
Documentation | 😀 |
Docstrings | 😀 |
Tests | 😀 |
Examples | 😀 |
RepositoryActivity | 😀 |
CI | 🥺 |
I decided to continue reviewing the template engines. Our today's library implements Mustache syntax, which also implemented for many other languages.
Mustache's
syntax is very simple and does not allow to write complex application logic. You will find some examples in this documentation:
http://mustache.github.io/mustache.5.html
Let's try to rewrite our performance test from the zenekindarl post to Mustache
!
POFTHEDAY> (mustache:define render
"
<title>{{title}}</title>
<ul>
{{#items}}<li>{{value}}</li>{{/items}}
</ul>
")
POFTHEDAY> (with-output-to-string (out)
(render '((:title . "Foo Bar")
(:items .
(((:value . "One"))
((:value . "Two"))
((:value . "Three")))))
out))
"
<title>Foo Bar</title>
<ul>
<li>One</li><li>Two</li><li>Three</li>
</ul>
"
POFTHEDAY> (time
(loop with context = '((:title . "Foo Bar")
(:items .
(((:value . "One"))
((:value . "Two"))
((:value . "Three")))))
repeat 1000000
do (with-output-to-string (out)
(render context out))))
Evaluation took:
5.213 seconds of real time
5.252826 seconds of total run time (5.155530 user, 0.097296 system)
[ Run times consist of 0.445 seconds GC time, and 4.808 seconds non-GC time. ]
100.77% CPU
11,510,317,038 processor cycles
4,319,993,136 bytes consed
So, the results are slightly slower than Spinneret
is almost as slow as Python's Jinja2
:
That is because cl-mustache's compile-template
function does not do the real compilation.
It only parses the template and returns a lambda which iterates and calls generic functions in runtime during rendering step.
To conclude, use cl-mustache
if you really want to limit the amount of logic on the frontend.
If you have some other template engines in mind, please, leave comments and I'll make a review.