Handlebars.js & Mustache.js Benchmarks


Yehuda Katz just released Handlebars.js, a compiled javascript Mustache implementation, similar to Mustache.js with some useful additional features. The README mentions,
"In a rough performance test, precompiled Handlebars.js templates rendered in about half the time of Mustache templates. It would be a shame if it were any other way, since they were precompiled, but the difference in architecture does have some big performance advantages."
Interested in the specifics, I did some benchmarking based on Brian Landau's Benchmarking Javascript Templating Libraries and came up with the following results. I made some tweaks to the overall benchmarking approach, isolating the actual template rendering from any DOM manipulation and removing the setTimeout mentioned in PPK’s benchmarking methodology as it was no longer necessary. The time it took to render the template 5k times was recorded and averaged out over 10 tries. Not terribly scientific, but hopefully good enough to show that in both simple and iterative cases Handlebars.js is about 2x as fast. The code I used to achieve these results is in my js-templates-benchmark repo.