Scriban
# Benchmarks
Latest benchmark update: 07 March 2019
> NOTE: This is a micro benchmark, so results may vary vastly on use cases. The goal here is to demonstrate on a very simple example how the different engines behave
> Also, while Scriban is compared here to `liquid` and `mustache` like templating engines, you should keep in mind that language-wise, Scriban is allowing a lot more language constructions/expressions.
The benchmark was performed on two aspects of the libraries:
- The [**Parser Benchmark**](#parser-benchmarks): How long does it take to parse a template to a runtime representation? How much memory is used?
- The [**Rendering Benchmark**](#rendering-benchmarks): How long does it take to render a template with some input datas? How much memory is used?
Libraries used in this comparison:
- Scriban (2.0.0-alpha-006), Syntax: Scriban
- [Fluid](https://github.com/sebastienros/fluid/) (Fluid.Core.1.0.0-beta-9545), Syntax: Liquid based
- [DotLiquid](https://github.com/dotliquid/dotliquid) (2.0.298), Syntax: Liquid based
- [Stubble](https://github.com/StubbleOrg/Stubble) (1.2.7), Syntax: Mustache+ based
- [Nustache](https://github.com/jdiamond/Nustache) (1.16.0.8), Syntax: Mustache based
- [Handlebars.NET](https://github.com/rexm/Handlebars.Net) (1.9.5), Syntax: Handlebars based
- [Cottle](https://github.com/r3c/cottle) (1.4.2), Syntax: Cottle
We are also adding [Razor](https://github.com/aspnet/Razor) (2.0.0), Syntax: Razor/C#, not in the charts and in the raw results. This is not a relevant comparison for the fact that it a not a "end-user" text templating engine (not safe) but it gives some insights about the best raw performance you can achieve with it for the rendering part, as it is generating very raw pre-compiler C# code that is basically issuing a bunch of `WriteLiteral(text_as_is)`, so you can't really do better here in terms of performance.
For benchmarking, we are using the fantastic [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet)
See the [Scriban.Benchmark/Program.cs](../src/Scriban.Benchmarks/Program.cs) for details of the benchmark implementation.
[:top:](#benchmarks)
## Overall results
For the parser part:
- **Scriban parser is 3x to 6x times** faster compared to liquid based templating parsers
- **Scriban parser takes 3x to 40x times less memory** compared to other templating parsers
If you look at Razor (which is again, not really fair), `scriban` is roughly 1000x times faster than Razor for parsing a template. Which is perfectly normal, as Razor is involving the full Roslyn/C# compiler here. It is taking a lot more memory...etc. But it is generating an ultra efficient renderer.
For the rendering part:
- **Scriban is 1.2x to x14 times faster** than most of the other templating engines (Note that the new version of Fluid in this test is now 5-8% faster than Scriban on the rendering side)
- **Scriban takes 3x to x65 times less memory** compared to most of other templating engines
In comparison to Razor, `scriban` is only 4-5 times slower than Razor, which is fairly honorable, considering how much raw is a compiled Razor template.
In the following sections, you will find benchmark details.
[:top:](#benchmarks)
## Parser Benchmarks
The methodology is to compile the following Scriban script:
```html
-
{{ for product in products }}
-
{{ product.name }}
Only {{ product.price }} {{ product.description | string.truncate 15 }}
{{ end }}
-
{% for product in products %}
-
{{ product.name }}
Only {{ product.price }} {{ product.description | truncate: 15 }}
{% endfor %}
-
{{#products}}
-
{{ name }}
Only {{ price }} {{#truncate}}{{description}}{{/truncate}}
{{/products}}
-
{ for product in products:
-
{ product.Name }
Only { product.Price } { string.truncate(product.Description, 15) }
}