Skip to content

Instantly share code, notes, and snippets.

@AGhost-7
Last active April 17, 2016 02:23
Show Gist options
  • Select an option

  • Save AGhost-7/9025111460e42c73c6b9d2173657626a to your computer and use it in GitHub Desktop.

Select an option

Save AGhost-7/9025111460e42c73c6b9d2173657626a to your computer and use it in GitHub Desktop.
Bechmark for various templates
/* jshint esversion: 6 */
const Benchmark = require('benchmark');
const haml = require('hamljs');
const hogan = require('hogan.js');
const pug = require('pug');
const ejs = require('ejs');
const suite = new Benchmark.Suite();
suite
.add('haml.js', () => {
const h = haml.compile('%p hello #{name}');
return () => {
h({ name: 'foobar' });
};
}())
.add('hogan.js', () => {
const h = hogan.compile('<p>hello {{name}}</p>');
return () => {
h.render({ name: 'foobar' });
};
}())
.add('pug', () => {
const h = pug.compile('p hello #{name}');
return () => {
h({ name: 'foobar' });
};
}())
.add('ejs', () => {
const h = ejs.compile('<p>hello <%= name %></p>');
return () => {
h({ name: 'foobar' });
};
}())
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', function() {
console.log('Winner is:', this.filter('fastest').map('name'));
})
.run({ async: true });
  • haml.js x 724,557 ops/sec ±4.68% (74 runs sampled)
  • hogan.js x 11,141,376 ops/sec ±3.76% (82 runs sampled)
  • pug x 4,055,327 ops/sec ±4.10% (77 runs sampled)
  • ejs x 338,938 ops/sec ±4.29% (78 runs sampled)

Winner is: hogan.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment