Permalink
Browse files

Added ejs benchmarks

  • Loading branch information...
1 parent 36d3d72 commit 6e196f39f3b7c1563e90f35645a054713446fb48 @tj tj committed Aug 26, 2010
Showing with 46 additions and 2 deletions.
  1. +3 −0 .gitmodules
  2. +2 −1 Makefile
  3. +8 −1 benchmarks/common.js
  4. +1 −0 benchmarks/ejs
  5. +24 −0 benchmarks/ejs.js
  6. +8 −0 benchmarks/example.ejs
View
@@ -10,3 +10,6 @@
[submodule "benchmarks/haml-js"]
path = benchmarks/haml-js
url = git://github.com/creationix/haml-js.git
+[submodule "benchmarks/ejs"]
+ path = benchmarks/ejs
+ url = git://github.com/visionmedia/ejs.git
View
@@ -24,6 +24,7 @@ api.html: lib/jade.js
benchmark:
@node benchmarks/jade.js && \
- node benchmarks/haml.js
+ node benchmarks/haml.js && \
+ node benchmarks/ejs.js
.PHONY: install uninstall test example benchmark
View
@@ -1,4 +1,10 @@
+/**
+ * Module dependencies.
+ */
+
+var sys = require('sys');
+
var currentLabel,
startTime;
@@ -7,12 +13,13 @@ exports.times = 5000;
exports.start = function(label){
currentLabel = label;
startTime = new Date;
+ sys.print(' - \x1b[33m' + currentLabel + '\x1b[0m: ');
};
exports.stop = function(){
var stopTime = new Date,
duration = stopTime - startTime;
- console.log('%s: %dms', currentLabel, duration);
+ sys.print(duration + ' ms\n');
};
exports.locals = {
Submodule ejs added at 56f5ea
View
@@ -0,0 +1,24 @@
+
+/**
+ * Module dependencies.
+ */
+
+var bm = require('./common'),
+ ejs = require('./ejs/lib/ejs'),
+ fs = require('fs');
+
+var str = fs.readFileSync(__dirname + '/example.ejs', 'ascii');
+
+var n = bm.times;
+bm.start('ejs compilation');
+while (n--) {
+ ejs.render(str, { locals: bm.locals });
+}
+bm.stop();
+
+var n = bm.times;
+bm.start('ejs execution');
+while (n--) {
+ ejs.render(str, { locals: bm.locals, cache: true, filename: 'example.ejs' });
+}
+bm.stop();
View
@@ -0,0 +1,8 @@
+<ul>
+ <li><%- one %></li>
+ <li><%- two %></li>
+ <li><%- three %></li>
+ <% items.forEach(function(item){ %>
+ <li><%- item %></li>
+ <% }) %>
+</ul>

0 comments on commit 6e196f3

Please sign in to comment.