Render speed results in milliseconds, for 3 different templates, number of runs 1M.
Data | Erlang/bbmustache | Erlang/fast | Go | Scala | OCaml |
---|---|---|---|---|---|
Template 1 | 23,971 | 33,649 | 35,620 | 80,622 | 19,541 |
Template 2 | 16,471 | 8,330 | 11,600 | 17,357 | 5,865 |
Template 3 | 31,246 | 12,442 | 16,188 | 33,220 | 9,034 |
Data | Erlang/bbmustache | Erlang/erlydtl | Go | Scala/scalate | Scala/mustache | OCaml |
---|---|---|---|---|---|---|
Template 1 | 1,814 | 29,495 | 19,406 | 11,156 | 5,646 | 1,007 |
Template 2 | 2,525 | 7,293 | 7,545 | 6,250 | 3,482 | 1,452 |
Template 3 | 2,265 | x | 9,854 | 4,947 | 3,965 | 2,269 |
template 1 -- 65 lines, 5020 bytes, variables only
template 2 -- 11 lines, 383 bytes, variables only
template 3 -- 20 lines, 207 bytes, with if, loop etc constructs
The first Erlang/bbmustache implementation uses the bbmustache library https://github.com/soranoba/bbmustache
- Erlang/OTP 18 erts-7.1 -bbmustache, "1.0.4"
The second Erlang/fast implementation uses a simple function based on binary:split which can replace variables in a template.
bbmustache precompiled: mustache_pc_bm.erl
It is important for bbmustache to use the {key_type, string} option (or no options, this will be the default). {key_type, binary} slows down rendering, significantly in some cases.
And to compare ErlyDTL https://github.com/erlydtl/erlydtl with precompilation: mustache_bm3.erl (For the 3rd template, the test was not done, because it is incompatible with the DTL).
go1.3.3 linux/amd64
https://github.com/cbroglie/mustache (In Go tradition -- unknown version. Commit 6857e4b493bdb8d4b1931446eb41704aeb4c28cb at the time of the test)
Tests, of course, on the compiled binary, not in the interpreter.
Tried 3 more libs:
- https://github.com/aymerick/raymond -- this one is very slow
- https://github.com/ChrisBuchholz/gostache -- does not work with maps, requires specific bindings
- https://github.com/alexkappa/mustache -- very slow
First I took the Scalate library
- scala 2.10.6
- "org.fusesource.scalate" %% "scalate-core" % "1.6.1"
- https://github.com/scale/scale
The option without precompiling the template MustacheBM.scala is terribly slow:
- 10 renders -- 3970ms
- 100 renders -- 19254ms
But with precompilation MustachePC_BM.scala shows good results.
Tried another library: https://github.com/vspy/scala-mustache
MustacheBM.scala MustachePC_BM.scala
The results are comparable to other languages.
##OCaml
- Ocaml 4.02.1
- ezjsonm 0.4.1
- mustache 1.0.1 https://github.com/rgrinberg/ocaml-mustache
Tests on a binary compiled into native code.
mustache_bm.ml mustache_pc_bm.ml
The library generates an error if the binding does not contain a value for a variable in the template. Maybe it's configurable.
OCaml is the fastest.
Erlang/bbmustache with precompilation works just as well as OCaml. Without precompilation, it's worse, but not bad compared to other languages.