node-templates icon indicating copy to clipboard operation
node-templates copied to clipboard

Update to use the latest Swig version (1.0.0-rc3)

Open lexagosto opened this issue 11 years ago • 0 comments

Hello, I've just patched the bench suite to upgrade both Swig (to 1.0.0-rc3) and EJS (to 0.8.4).

This is what I actually did, because I was interested in evaluating those templates by performances.

diff --git a/lib/languages/swig.js b/lib/languages/swig.js
index 37b1318..cd97e56 100644
--- a/lib/languages/swig.js
+++ b/lib/languages/swig.js
@@ -13,16 +13,13 @@ var swig = require('swig'),
     },
     tpl = {};

-swig.init({
-    root: __dirname + '/../templates/swig'
-});

 exports.compile = function (type, callback) {
-    tpl[type] = swig.fromString(files[type]);
+    tpl[type] = swig.compile(files[type]);
     callback();
 };

 exports.render = function (type, callback) {
-    tpl[type].render(data);
+    tpl[type](data);
     callback();
 };

While I left the ejs example as-is since it was running properly.

Other tests was not modified, by the way I was surprised by results:

swig complete
Raw:
 > 3.4625374625374628
 > 3.195804195804196
 > 3.4115884115884114
 > 3.3766233766233764
 > 3.4015984015984015
 > 3.5944055944055946
 > 3.2987012987012987
 > 3.4645354645354645
Average (mean) 3.4007242757242757

ejs complete
Raw:
 > 12.32967032967033
 > 12.218781218781219
 > 12.713286713286713
 > 12.401598401598402
 > 12.577422577422578
 > 12.305694305694306
 > 12.722277722277722
 > 12.607392607392608
Average (mean) 12.484515484515486

Why is swig so slow? Am I doing something wrong? Or it's just because of the release-candidate status? (I did not test with other versions). EJS performs 4x better actually.

Note: I did not modify templates so maybe something there is outdated justifying these results.

P.S. once I complete my tests I'll make a pull request.

Thanks.

lexagosto avatar Sep 22 '13 11:09 lexagosto