From fbe17adacadbebc6a08bdbbc748837c1b77f22e6 Mon Sep 17 00:00:00 2001 From: Roel van Uden Date: Mon, 4 Mar 2013 15:19:33 +0100 Subject: [PATCH 1/5] Gaikan 1.3.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f88f1f..f81eb9d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "handlebars": "1.0.9", "coffeekup": "0.3.1", "underscore": "1.4.4", - "gaikan": "1.3.4" + "gaikan": "1.3.5" } } From b84cbdd0510ac99d19f7f223721a1cc7374699d7 Mon Sep 17 00:00:00 2001 From: Roel van Uden Date: Sun, 10 Mar 2013 01:03:26 +0100 Subject: [PATCH 2/5] Gaikan 1.3.10: Performance influencing patch. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f81eb9d..43e3392 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "handlebars": "1.0.9", "coffeekup": "0.3.1", "underscore": "1.4.4", - "gaikan": "1.3.5" + "gaikan": "1.3.10" } } From 58524257082578449c1fef8f474b9d1793048275 Mon Sep 17 00:00:00 2001 From: Roel van Uden Date: Sun, 10 Mar 2013 10:38:46 +0100 Subject: [PATCH 3/5] Gaikan 1.3.11: Performance influencing patch. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43e3392..23177b6 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "handlebars": "1.0.9", "coffeekup": "0.3.1", "underscore": "1.4.4", - "gaikan": "1.3.10" + "gaikan": "1.3.11" } } From 39422e9e088697e06c1b73054239283016a4fb70 Mon Sep 17 00:00:00 2001 From: Deathspike Date: Sun, 9 Mar 2014 16:17:09 +0100 Subject: [PATCH 4/5] Gaikan 2.0.0-rc1 with better reporting --- .gitignore | 1 + README.md | 121 ++++++++++++-------------------------- benchmark.js | 27 +++++++++ gaikan/gaikan.js | 15 ++--- gaikan/tpl_escaped.html | 18 +++--- gaikan/tpl_unescaped.html | 18 +++--- package.json | 2 +- 7 files changed, 90 insertions(+), 112 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/README.md b/README.md index 989fe3e..e9c2594 100644 --- a/README.md +++ b/README.md @@ -14,93 +14,46 @@ - [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 diff --git a/benchmark.js b/benchmark.js index b212590..93f74da 100644 --- a/benchmark.js +++ b/benchmark.js @@ -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(); @@ -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')); + } } }; diff --git a/gaikan/gaikan.js b/gaikan/gaikan.js index a821074..faf8f69 100644 --- a/gaikan/gaikan.js +++ b/gaikan/gaikan.js @@ -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); }; \ No newline at end of file diff --git a/gaikan/tpl_escaped.html b/gaikan/tpl_escaped.html index 1202e36..bcb447c 100644 --- a/gaikan/tpl_escaped.html +++ b/gaikan/tpl_escaped.html @@ -1,15 +1,15 @@ - #{data.title} + #{root.title} -

#{data.text}

- - #{data.name} -

#{data.description}

-
- +

#{root.text}

+
+ #{project.name} +

#{project.description}

+
+
No projects - +
- + \ No newline at end of file diff --git a/gaikan/tpl_unescaped.html b/gaikan/tpl_unescaped.html index de1069e..066a915 100644 --- a/gaikan/tpl_unescaped.html +++ b/gaikan/tpl_unescaped.html @@ -1,15 +1,15 @@ - !{data.title} + !{root.title} -

!{data.text}

- - !{data.name} -

!{data.description}

-
- +

!{root.text}

+
+ !{project.name} +

!{project.description}

+
+
No projects - +
- + \ No newline at end of file diff --git a/package.json b/package.json index 23177b6..c98cd37 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "handlebars": "1.0.9", "coffeekup": "0.3.1", "underscore": "1.4.4", - "gaikan": "1.3.11" + "gaikan": "2.0.0-rc1" } } From 65b58b1ceca918b483394f89fcdaf45cfc43907a Mon Sep 17 00:00:00 2001 From: Roel van Uden Date: Sun, 16 Mar 2014 11:42:23 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9c2594..9c3fb54 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ ## 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