Giter VIP home page Giter VIP logo

mustache_benchmark's Introduction

Mustache template engine, rendering in different languages

Render speed results in milliseconds, for 3 different templates, number of runs 1M.

No template precompilation

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

From precompiled templates

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

Templates

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

Erlang

The first Erlang/bbmustache implementation uses the bbmustache library https://github.com/soranoba/bbmustache

  • Erlang/OTP 18 erts-7.1 -bbmustache, "1.0.4"

mustache_bm.erl

The second Erlang/fast implementation uses a simple function based on binary:split which can replace variables in a template.

mustache_bm2.erl

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).

Go

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.

mustache_bm.go

Tried 3 more libs:

Scala

First I took the Scalate library

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

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.

Conclusions

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.

mustache_benchmark's People

Contributors

batiati avatar yzh44yzh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.