Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gaikan 1.3.5 #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
123 changes: 38 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,96 +14,49 @@
- [Jade](https://github.com/visionmedia/jade) v0.28.1 ([website](http://jade-lang.com/))
- [Swig](https://github.com/paularmstrong/swig) v0.13.5
- [Underscore](https://github.com/documentcloud/underscore) v1.4.4 ([website](http://underscorejs.org/))
- [Gaikan](https://github.com/Deathspike/gaikan) v1.2.1

## Test environment

- CPU: Intel Core i5 450M 2.4Ghz
- OS: Ubuntu Server 12.04
- Node.JS version: 0.8.20
- [Gaikan](https://github.com/Deathspike/gaikan) v2.0.0

## Results

Rendering 100000 templates:

ECT
Escaped : 2296ms
Unescaped : 136ms
Total : 2432ms

Gaikan
Escaped : 3012ms
Unescaped : 33ms
Total : 3045ms

Dust
Escaped : 2687ms
Unescaped : 423ms
Total : 3110ms

Hogan.js
Escaped : 3464ms
Unescaped : 793ms
Total : 4257ms

Fest
Escaped : 4319ms
Unescaped : 278ms
Total : 4597ms

EJS without `with`
Escaped : 4744ms
Unescaped : 494ms
Total : 5238ms

doT
Escaped : 5305ms
Unescaped : 91ms
Total : 5396ms

Swig
Escaped : 5202ms
Unescaped : 405ms
Total : 5607ms

Underscore
Escaped : 6045ms
Unescaped : 2729ms
Total : 8774ms

Eco
Escaped : 8238ms
Unescaped : 1003ms
Total : 9241ms

EJS
Escaped : 6527ms
Unescaped : 2835ms
Total : 9362ms

Handlebars.js
Escaped : 8238ms
Unescaped : 2756ms
Total : 10994ms

Jade without `with`
Escaped : 9671ms
Unescaped : 3365ms
Total : 13036ms

CoffeeKup
Escaped : 5082ms
Unescaped : 10555ms
Total : 15637ms

Jade
Escaped : 17778ms
Unescaped : 12013ms
Total : 29791ms

### Linux Ubuntu 12.04, NodeJS 0.10.26 (100.000x)

Gaikan ( 2090ms) - fastest
ECT ( 2334ms) - 12% slower
Fest ( 2791ms) - 34% slower
Dust ( 3030ms) - 45% slower
doT ( 3940ms) - 89% slower
Hogan.js ( 3977ms) - 90% slower
EJS without `with` ( 5190ms) - 148% slower
Swig ( 5258ms) - 152% slower
Underscore ( 6154ms) - 194% slower
Handlebars.js ( 7255ms) - 247% slower
Eco ( 8315ms) - 298% slower
EJS ( 9059ms) - 333% slower
Jade without `with` (10973ms) - 425% slower
CoffeeKup (11062ms) - 429% slower
Jade (27295ms) - 1206% slower

### Windows 7 x64 SP1, NodeJS 0.10.26 (100.000x)

Gaikan ( 2147ms) - fastest
Fest ( 2535ms) - 18% slower
doT ( 3524ms) - 64% slower
Underscore ( 5108ms) - 138% slower
Handlebars.js ( 5734ms) - 167% slower
ECT ( 7223ms) - 236% slower
EJS without `with` ( 8732ms) - 307% slower
Dust ( 9136ms) - 326% slower
Hogan.js ( 9960ms) - 364% slower
Swig (10240ms) - 377% slower
Eco (12292ms) - 473% slower
Jade without `with` (13510ms) - 529% slower
EJS (14917ms) - 595% slower
CoffeeKup (15319ms) - 614% slower
Jade (34000ms) - 1484% slower

## Usage

git clone git://github.com/baryshev/template-benchmark.git
git clone git://github.com/Deathspike/template-benchmark.git
cd template-benchmark
npm install
node ./benchmark.js
27 changes: 27 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ var samples = [
{ name : 'ECT', sample : ect },
];

var results = [];
var pad = function (val, num, pre) {
val = typeof val === 'string' ? val : '' + val;
while (val.length < num) val = (pre ? ' ' : '') + val + (pre ? '' : ' ');
return val;
};
var runTests = function () {
if (samples.length) {
var sample = samples.pop();
Expand All @@ -82,9 +88,30 @@ var runTests = function () {
console.log(' Unescaped : ' + resultUnescaped + 'ms');
console.log(' Total : ' + (result + resultUnescaped) + 'ms');
console.log('');
results.push({
name: name,
escaped: result,
unescaped: resultUnescaped,
total: result + resultUnescaped
});
runTests();
});
});
} else {
console.log('Performance report for ' + count + ' templates (' + process.platform + '):\n');
results.sort(function (a, b) {
var x = a.total;
var y = b.total;
return x < y ? -1 : (x > y ? 1 : 0);
});
var fastest = results[0].total;
for (var i = 0; i < results.length; i += 1) {
var result = results[i];
var percentage = Math.round((100 / fastest * result.total) - 100);
console.log(pad(result.name, 20) +
' (' + pad(result.total, 5, true) + 'ms)' +
(i == 0 ? ' - fastest' : ' - ' + percentage + '% slower'));
}
}
};

Expand Down
15 changes: 6 additions & 9 deletions gaikan/gaikan.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
'use strict';
var gaikan = require('gaikan');
var compiled;
var tplData;

gaikan.options.directories = ['gaikan'];

module.exports.prepare = function (data, done) {
tplData = data;
compiled = gaikan.compileFile('tpl_escaped', 'gaikan', undefined, true);
/*gaikan.explainFile('tpl_escaped', 'gaikan', function (js) {
console.log(js.replace(/\t/g, ' '));
});*/
compiled = gaikan.compileFromFile('tpl_escaped');
done();
};

module.exports.prepareUnescaped = function (data, done) {
tplData = data;
compiled = gaikan.compileFile('tpl_unescaped', 'gaikan', undefined, true);
/*gaikan.explainFile('tpl_unescaped', 'gaikan', function (js) {
console.log(js.replace(/\t/g, ' '));
});*/
compiled = gaikan.compileFromFile('tpl_unescaped');
done();
};

module.exports.step = function (done) {
var html = compiled(tplData);
var html = compiled(gaikan, tplData);
done(undefined, html);
};
18 changes: 9 additions & 9 deletions gaikan/tpl_escaped.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<html>
<head>
<title>#{data.title}</title>
<title>#{root.title}</title>
</head>
<body>
<p>#{data.text}</p>
<ins data-for="data.projects">
<a href="#{data.url}">#{data.name}</a>
<p>#{data.description}</p>
</ins>
<ins data-if="!data.projects">
<p>#{root.text}</p>
<div data-for="project in root.projects" data-extract>
<a href="#{project.url}">#{project.name}</a>
<p>#{project.description}</p>
</div>
<div data-if="!root.projects.length" data-extract>
No projects
</ins>
</div>
</body>
</html>
</html>
18 changes: 9 additions & 9 deletions gaikan/tpl_unescaped.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<html>
<head>
<title>!{data.title}</title>
<title>!{root.title}</title>
</head>
<body>
<p>!{data.text}</p>
<ins data-for="data.projects">
<a href="!{data.url}">!{data.name}</a>
<p>!{data.description}</p>
</ins>
<ins data-if="!data.projects">
<p>!{root.text}</p>
<div data-for="project in root.projects" data-extract>
<a href="!{project.url}">!{project.name}</a>
<p>!{project.description}</p>
</div>
<div data-if="!root.projects.length" data-extract>
No projects
</ins>
</div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"handlebars": "1.0.9",
"coffeekup": "0.3.1",
"underscore": "1.4.4",
"gaikan": "1.3.4"
"gaikan": "2.0.0-rc1"
}
}