Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Handlebars vs Hogan vs Mustache rendering
(version: 0)
Comparing performance of:
handlebarsRenderer({thing:"hello"}); vs hoganRenderer.render({thing:"hello"});
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.6/handlebars.min.js" integrity="sha512-zT3zHcFYbQwjHdKjCu6OMmETx8fJA9S7E6W7kBeFxultf75OPTYUJigEKX58qgyQMi1m1EgenfjMXlRZG8BXaw==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/4.0.1/mustache.min.js" integrity="sha512-6AXIWogbKpsHvoZJrJtHpIYES4wP8czSj0zk7ZfwOYS8GWYFNSykwdfapt7yQc4ikZytemBu+QyVObzBHJMwYg==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/hogan.js/3.0.2/hogan.min.js" integrity="sha512-F6j8lc1UBrmZHqUGreg4gNVVMCehTbf/LU0s/nnsQJYVeFSdpci+fcL48gsTd1Fbf08sD/kL+is2QiEssvJ70g==" crossorigin="anonymous"></script>
Script Preparation code:
var template = "<strong>This is a slightly more complicated {{thing}}.</strong>.\n{{! Just ignore this business. }}\nCheck this out:\n{{#hasThings}}\n<ul>\n{{#things}}\n<li class={{className}}>{{word}}</li>\n{{/things}}</ul>.\n{{/hasThings}}\n{{^hasThings}}\n\n<small>Nothing to check out...</small>\n{{/hasThings}}"; var handlebarsRenderer = Handlebars.compile(template); var hoganRenderer = Hogan.compile(template);
Tests:
handlebarsRenderer({thing:"hello"});
handlebarsRenderer({thing:"hello"});
hoganRenderer.render({thing:"hello"});
hoganRenderer.render({thing:"hello"});
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
handlebarsRenderer({thing:"hello"});
hoganRenderer.render({thing:"hello"});
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
handlebarsRenderer({thing:"hello"});
616718.5 Ops/sec
hoganRenderer.render({thing:"hello"});
9193270.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares the rendering performance of three templating libraries: Handlebars, Hogan, and Mustache. The goal is to determine which library is faster when rendering a specific template with some data. **Template Analysis** The template contains several directives: * `{{thing}}`: This will be replaced with the value of the "thing" variable. * `{{! Just ignore this business. }}`: This line will be ignored during rendering, and its contents are not relevant to the benchmark. * `{{#hasThings}}`: This is a loop that iterates over an array of objects (`things`). Each object has a `word` property, which will be rendered as an `<li>` element with a specific class name. * `{{^hasThings}}`: This is another loop that iterates over the same array, but this time only when the `hasThings` condition is false. **Library Comparison** The three libraries being tested are: 1. **Handlebars**: A popular templating engine for JavaScript applications. 2. **Hogan**: Another templating library, similar to Handlebars, but with some performance optimizations. 3. **Mustache**: A lightweight templating engine designed for simplicity and ease of use. **Options Compared** The benchmark compares two rendering approaches: 1. **Handlebars Renderer**: The `handlebarsRenderer` function is used to render the template with the provided data ({{thing:"hello"}}). 2. **Hogan Renderer**: The `hoganRenderer.render()` method is used to render the same template with the same data. **Pros and Cons of Each Approach** * **Handlebars Renderer**: + Pros: Handlebars has a large community and extensive documentation, making it easy to learn and use. + Cons: It may have performance overhead due to its complexity. * **Hogan Renderer**: + Pros: Hogan is designed for performance and simplicity, making it suitable for applications where rendering speed is crucial. + Cons: Its smaller community and less comprehensive documentation might make it more challenging to learn and use. **Library-Specific Considerations** * **Handlebars**: Handlebars has a strong focus on safety features, such as escaping and sanitization, which can impact performance. However, its robustness and flexibility make it a popular choice for many applications. * **Hogan**: Hogan is designed to be fast and lightweight, making it suitable for applications where rendering speed is essential. Its simplicity comes at the cost of less comprehensive documentation and support. **Other Alternatives** If Handlebars or Hogan are not ideal choices, other templating libraries could be considered: 1. **Mustache**: A lightweight and simple templating engine that's easy to learn and use. 2. **Pug** (formerly Jade): A popular templating engine for Node.js applications, known for its performance and ease of use. 3. **Nunjucks**: A templating library developed by Instagram, offering a balance between simplicity and performance. Keep in mind that the choice of templating library ultimately depends on the specific requirements and constraints of your project.
Related benchmarks:
mustache rendering performance-fix
Handlebars vs Hogan vs Mustache
Hogan vs Mustache vs HB
Handlebars vs Hogan vs Mustache (Updated versions2)
Comments
Confirm delete:
Do you really want to delete benchmark?