zenekindarl

2017-11-30

A fast precompiling template engine

Upstream URL

github.com/KeenS/zenekindarl

Author

κeen

License

README

Build Status Coverage Status

Zenekindarl

Expected to be a fast, flexible, extensible, low memory usage, async, concurrent template engine.

Usage

Like this

(render "Hello {{var name}}!!"
        :name "κeen")
(let ((renderer (compile-template-string :stream "Hello {{var name}}!!")))
  (funcall renderer *standard-output* :name "κeen"))

.

For more information, see docstring

Instant Benchmark

Zenekindarl perform x16 as fast as a template engine in Python in the following instant benchmark.

Benchmark

Template enginesTime[sec]
Zenekindarl, SBCL 1.1.81.365
Jinja2, Python 2.7.524.07

The benchmark code for Zenekindarl:

> (time
   (with-open-file (out #P"~/Desktop/out" :direction :output :if-exists :supersede)
     (let ((fun (zenekindarl:compile-template-string :stream "Hello {{var name}}!!")))
       (loop repeat 1000000
          do (funcall fun out :name "κeen")))))
Evaluation took:
1.625 seconds of real time
1.364707 seconds of total run time (1.302198 user, 0.062509 system)
[ Run times consist of 0.042 seconds GC time, and 1.323 seconds non-GC time. ]
84.00% CPU
1 form interpreted
3 lambdas converted
3,265,218,807 processor cycles
528,706,464 bytes consed

The benchmark code for a template engine in Python:

$ cat te.py
from jinja2 import Template

template = Template( u'Hello {{ name }}!!' )

f = open( 'out', 'w' )
for i in range( 1000000 ):
  f.write( template.render( name=u'κeen' ).encode( 'utf-8' ) )

$ time python te.py
real    0m25.612s
user    0m24.069s
sys	    0m0.190s

Syntax

Variable

variables will be HTML escaped

{{var foo}}

Repeat

{{repeat 10}}hello{{endrepeat}}
{{repeat n as i}}<li>{{var i}}th item</li>{{endrepeat}}

Loop

<ol>
  {{loop items as item}}
  <li>{{var item}}</li>
  {{endloop}}
</ol>

If

{{if new-p}}New{{else}}Old{{endif}}

Insert

See code below
<code><pre>
{{insert "snippet.lisp"}}
</pre></code>

Include

<nav>
{{incude "sidebar.tmpl"}}
</nav>

Author

  • κeen

Copyright

Copyright (c) 2014 κeen

Dependencies (11)

  • alexandria
  • anaphora
  • babel
  • cl-annot
  • cl-ppcre
  • fast-io
  • flexi-streams
  • html-encode
  • maxpc
  • optima
  • prove

Dependents (0)

    • GitHub
    • Quicklisp