-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Description
Well, I'm not sure what happened here... 😀
The expected / advertised performance gain between Mustache and Handlebars... I was unable to (re)produce it...
I have made two benchmarks:
- minimal : 3 variables, 2 line template --> Mustache was faster in all scenarios (66%)
- maximal : 21 variables, 33 line template --> Handlebars was faster in all scenarios (6% for precompiled, 0.7% without precompilation)
This is the code:
https://github.com/itenium-be/TemplatingEngineBenchmarks
The code for maximal-precompiled:
import * as b from 'benny';
import Handlebars from 'handlebars';
import './maximal-precompiled-hbs.js';
import Mustache from 'mustache';
import { data, mustacheTemplate } from './maximal.js';
export default function suite() {
return b.suite(
'Template Engine Benchmark: Maximal precompiled',
b.add('Handlebars', () => {
Handlebars.templates['maximal-precompiled'](data);
}),
b.add('Mustache', () => {
Mustache.render(mustacheTemplate, data);
}),
b.cycle(),
b.complete(),
b.save({ file: 'maximal-precompiled', version: '1.0.0' }),
b.save({ file: 'maximal-precompiled', format: 'chart.html' }),
);
}
export const data = {
clientName: "Alice Corp",
consultantName: "John Doe",
projectName: "NextGen App",
projectMonth: "June 2025",
billingPeriodStart: "2025-06-01",
billingPeriodEnd: "2025-06-30",
invoiceNumber: "INV-2025-0625",
orderNumber: "PO-123456",
days: [
{ date: "2025-06-03", hours: 8, activity: "Feature implementation" },
{ date: "2025-06-04", hours: 6, activity: "Bug fixing" },
],
totalHours: 14,
hourlyRate: 85,
subtotal: 1190,
discount: true,
discountAmount: 190,
discountDescription: "Loyalty discount",
totalExclVat: 1000,
vatRate: 21,
vatAmount: 210,
totalInclVat: 1210,
notes: "Approved by client via email.",
companyName: "Itenium Consulting"
};
export const mustacheTemplate = `
Hello {{clientName}},
Please find below the summary for project **{{projectName}}** for the month of {{projectMonth}}.
Consultant: {{consultantName}}
Billing Period: {{billingPeriodStart}} - {{billingPeriodEnd}}
Invoice Number: {{invoiceNumber}}
{{#orderNumber}}Order Number: {{orderNumber}}{{/orderNumber}}
{{#days}}
- {{date}}: {{hours}}h - {{activity}}
{{/days}}
Total hours: {{totalHours}}
Hourly Rate: €{{hourlyRate}}
Subtotal: €{{subtotal}}
{{#discount}}
Discount: -€{{discountAmount}} ({{discountDescription}})
{{/discount}}
Total (excl. VAT): €{{totalExclVat}}
VAT ({{vatRate}}%): €{{vatAmount}}
**Grand Total: €{{totalInclVat}}**
{{#notes}}
Note: {{notes}}
{{/notes}}
The signed timesheet is attached to this message.
Kind regards,
The {{companyName}} team
`;
Am I doing something wrong? 😀
Metadata
Metadata
Assignees
Labels
No labels