Handlebars.js vs Mustache Rendering: Measured 1.172164x Faster
2026-11-21 (Node.js 24.21.0, 1000 records, 5 runs): Handlebars.js 4.7.10 median 186.439ms, 1.172164x faster than Mustache (218.537ms). 1 fixed template has a small gap; compatibility options decide.
As of 2026-11-21, across 5 repeated measurements of 1000 records in this site's isolated Node.js 24.21.0 environment, Handlebars.js 4.7.10 recorded a median rendering time of 186.439ms, which was 1.172164x faster than Mustache at 218.537ms. These figures are measured values obtained by directly running a comparison in this site's sandbox after precompiling and pre-parsing 1 identical fixed HTML template and 1000 records containing 5 child array items each (Raw Data (JSON), Handlebars.js GitHub Repository).
Original claim and this site's isolated measurement conditions
The original README claims that in earlier versions, precompiled Handlebars.js templates rendered in about half the time of Mustache templates, and that the rewritten current version of Handlebars renders five to up to 7 times faster than equivalent Mustache templates across several performance tests. The original text explains that these performance advantages come from architectural differences and outlines a benchmark suite configuration that measures compilation, execution, precompilation, and end-to-end performance across multiple templates of varying sizes and complexities.
To test this, the verification hypothesis established by this site checks whether Handlebars.js execution time (handlebarsMs) is shorter than Mustache (mustacheMs)—yielding a speed ratio (speedup) greater than 1—when precompiling and repeatedly rendering an identical nested-array template across 1000 records in a Node.js sandbox environment. In other words, we directly tested whether the original claim's multiplier of five to up to 7 times appears in the same direction under a single fixed-template repeated rendering condition (original README).
Noting the measurement conditions that differ from the original text first, instead of running the full benchmark suite from the original repository, this site measured only 1 fixed HTML template containing string interpolation ({{name}}, {{hometown}}) and array iteration ({{#kids}}...{{/kids}}) with a single-structure input dataset in a single Node.js container environment. Time spent on template compilation itself or file bundle loading was excluded from the measurement window, comparing only the pure rendering phase that repeatedly calls template functions already prepared in memory.
As of 2026-11-21, this site's isolated measurement environment consists of the aarch64 architecture, 2 Neoverse-N1 cores (with quota limits applied), 2048MB of memory, the Ubuntu 24.04.5 LTS operating system, and the Node.js 24.21.0 runtime; installing Handlebars.js version 4.7.10 and the comparison target package took 2.4 seconds and 5572808 bytes of disk space (Raw Data (JSON)).
Looking at the detailed execution conditions, the dataset consisted of 1000 records, each containing name and hometown strings along with 5 child array items. Before rendering, both libraries precompiled and pre-parsed the template using Handlebars.compile and Mustache.parse, and first verified that the rendered output strings for the first record matched completely. Next, after 5 warmup loops, the process of measuring the elapsed time to repeatedly render the same 1000-record array multiple times was executed 5 times in total within this site's isolated environment (Raw Data (JSON)).
Results: repeated rendering elapsed time and direction relative to original claim
As of 2026-11-21, across 5 repeated runs in this site's isolated environment, the median repeated rendering elapsed time for the template function generated by Handlebars.compile was 186.439ms, and the median repeated rendering elapsed time for Mustache.render was 218.537ms, recording a speedup (mustacheMs divided by handlebarsMs) of 1.172164 (Raw Data (JSON)).
- OS
- Ubuntu 24.04.5 LTS
- Processor
- Neoverse-N1 x2, CPUQuota 150%aarch64
- Memory
- 2,048 MB
- Runtime
- Node.js 24.21.0
- Tool tested
- Handlebars.js 4.7.10
- Repeats
- 5×
- Measured on
- 2026-11-21
Figure. The same input was measured 5 times. Bars show the median, the line below shows min–max, and dots show each run. Raw data (JSON)
View as table · raw data from 5 runs
| Run | Handlebars.compile | Mustache.render |
|---|---|---|
| 1 | 181.5 | 216.0 |
| 2 | 186.4 | 213.9 |
| 3 | 198.1 | 221.2 |
| 4 | 188.1 | 222.2 |
| 5 | 176.6 | 218.5 |
| Median | 186.4 | 218.5 |
| Min | 176.6 | 213.9 |
| Max | 198.1 | 222.2 |
| Metric | Median (median) | Min (min) | Max (max) | Unit | As-of Date and Source |
|---|---|---|---|---|---|
handlebarsMs (Handlebars.compile) | 186.439 | 176.554 | 198.143 | ms | 2026-11-21 (Raw Data (JSON)) |
mustacheMs (Mustache.render) | 218.537 | 213.909 | 222.184 | ms | 2026-11-21 (Raw Data (JSON)) |
speedup (mustacheMs / handlebarsMs) | 1.172164 | - | - | x (multiplier) | 2026-11-21 (Raw Data (JSON)) |
Examining the run-by-run measurements across all 5 runs shows that handlebarsMs was measured as shorter than mustacheMs in every run without any errors or output length mismatches (Raw Data (JSON)).
Execution Run (run) | handlebarsMs (ms) | mustacheMs (ms) | Total Execution Time wallMs (ms) | As-of Date and Source |
|---|---|---|---|---|
| 1 | 181.526 | 215.968 | 665.84 | 2026-11-21 (Raw Data (JSON)) |
| 2 | 186.439 | 213.909 | 666.761 | 2026-11-21 (Raw Data (JSON)) |
| 3 | 198.143 | 221.209 | 717.351 | 2026-11-21 (Raw Data (JSON)) |
| 4 | 188.125 | 222.184 | 666.762 | 2026-11-21 (Raw Data (JSON)) |
| 5 | 176.554 | 218.537 | 667.901 | 2026-11-21 (Raw Data (JSON)) |
Applying the directional evaluation criteria from the experimental design (same direction if speedup, defined as mustacheMs divided by handlebarsMs, is greater than 1; opposite direction if 1 or less; incomparable if an execution error or output mismatch occurs), the 5-run median speedup of 1.172164 is greater than 1, aligning in the same direction as the original claim that Handlebars.js is faster than Mustache. Across all 5 measurements, the maximum value of handlebarsMs (198.143ms) remained lower than the minimum value of mustacheMs (213.909ms), so the ranking did not change even when accounting for run-to-run variance (Raw Data (JSON)).
However, compared to the original README figure claiming it is five to up to 7 times faster across various performance tests, the speed ratio under this condition remained at 1.172164x (186.439ms vs. 218.537ms), showing a small relative difference between the two libraries.
The original README only states that precompiled templates have substantial performance advantages due to architectural differences and bases its claim on its own benchmark suite spanning multiple templates of varying complexities and sizes. By contrast, this site's experiment ran in an Ubuntu 24.04.5 LTS (aarch64), Node.js 24.21.0, and 2048MB memory container, executing Handlebars.compile and Mustache.parse in advance on 1 fixed HTML template and a 1000-record array containing 5 child array items each, and measured only the repeated rendering time—so the conditions differ from the original text. Whether these differences in conditions caused the difference in multiplier or whether other factors were involved cannot be determined from this measurement alone.
Reproduction script, measurement limitations, and engine selection criteria
The full measurement script executed 5 times in this site's sandbox as of 2026-11-21 is shown below (Raw Data (JSON)).
import { performance } from 'node:perf_hooks';
import Handlebars from 'handlebars';
import Mustache from 'mustache';
const source = '<p>Hello, my name is {{name}}. I am from {{hometown}}.</p><ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>';
const records = Array.from({ length: 1000 }, (_, i) => ({
name: `User_${i}`,
hometown: `City_${i % 50}, ST`,
kids: Array.from({ length: 5 }, (__, k) => ({
name: `Kid_${i}_${k}`,
age: String((i + k) % 18 + 1)
}))
}));
const hbTemplate = Handlebars.compile(source);
Mustache.parse(source);
if (hbTemplate(records[0]) !== Mustache.render(source, records[0])) {
throw new Error('Rendered output mismatch between Handlebars and Mustache');
}
for (let w = 0; w < 5; w++) {
for (let i = 0; i < records.length; i++) {
hbTemplate(records[i]);
Mustache.render(source, records[i]);
}
}
const iterations = 50;
let hbSink = 0;
const t0 = performance.now();
for (let r = 0; r < iterations; r++) {
for (let i = 0; i < records.length; i++) {
hbSink += hbTemplate(records[i]).length;
}
}
const handlebarsMs = performance.now() - t0;
let muSink = 0;
const t1 = performance.now();
for (let r = 0; r < iterations; r++) {
for (let i = 0; i < records.length; i++) {
muSink += Mustache.render(source, records[i]).length;
}
}
const mustacheMs = performance.now() - t1;
if (hbSink !== muSink) { throw new Error('Total output length mismatch');
}
console.log(JSON.stringify({
handlebarsMs: Number(handlebarsMs.toFixed(3)),
mustacheMs: Number(mustacheMs.toFixed(3))
}));
These measurement results (median handlebarsMs of 186.439ms, median mustacheMs of 218.537ms, and speedup of 1.172164) hold only under the condition of precompiling and pre-parsing 1 fixed HTML template and 1000 records containing 5 child array items each for repeated rendering in an isolated Ubuntu 24.04.5 LTS (aarch64), Node.js 24.21.0, and 2048MB memory environment (Raw Data (JSON)). Workloads that recompile templates on every request, initial startup times when precompiling templates into JavaScript files at build time, or performance on templates with deeply nested partials and custom helpers were not included in the scope of this measurement and remain unknown.
Furthermore, according to the Handlebars.js GitHub Repository documentation, Handlebars.js does not perform Mustache's recursive lookup by default, and enabling it requires turning on the compat flag at compile time. The original README notes that enabling the compat flag incurs a performance cost and recommends explicit path references for performance-critical tasks, meaning that the default-mode measurements from this test (186.439ms vs. 218.537ms) may not hold as-is when running existing Mustache templates in compat mode.
Checking the Handlebars.js 4.7.10 Release Notes confirms that in version 4.7.10, {{#each}} was improved to lazily iterate over iterables such as Map, Set, and generators without copying them into an array first, alongside security fixes including <!-- and <script escaping in precompiled output and AST validation. Therefore, if you are repeatedly rendering datasets on the scale of 1000 records with 5 child array items using a precompiled fixed template in a Node.js 24.21.0 environment and need helpers, block expressions, and the security-patched features of version 4.7.10, choose Handlebars.js; if you have existing templates that rely on Mustache-specific specifications such as recursive lookup, padded syntax ({{ > partial }}), or alternative delimiters, keeping Mustache is more appropriate than switching engines solely for a 1.172164x raw rendering speed difference.
Related posts
cbor-x 1.6.9 vs. Node.js Built-in JSON: Serialization Speed and Size
In 7 isolated runs (1000 records, Node.js 24.21.0, 2026-11-17), cbor-x 1.6.9 was slower than built-in JSON (total median 622.876 ms vs 445.555 ms) but cut output: 208297 B to 161665 B (-22.387264%).
Mutative vs. Immer Immutable State Update Speed Comparison
In 7 sandbox runs on 2026-11-16 (Mutative 2.0.2 vs Immer), median 1000-item array combined updates fell 295.462ms → 126.116ms (2.34x) and 500-record nested updates 470.486ms → 204.711ms (2.30x).
ollama-js 0.6.4 Behavior and Adoption Criteria From Benchmarks
2026-11-10 isolated test (/lab/ollama-js-first-run.json): ollama-js 0.6.4 loaded (10.496ms) and encoded images (0.059ms) with no server; list (43.18ms) and chat (4.398ms) failed with TypeError.
Written by AI from public sources; numbers and claims are checked against those sources before publishing.