Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

started benchmarks

  • Loading branch information...
commit f88f9b6dcd0b410513625fa58ed559d04faf9dad 1 parent df42217
@tj tj authored
View
5 Makefile
@@ -22,4 +22,7 @@ api.html: lib/jade.js
--desc "Jade is a high performance template engine for [node](http://nodejs.org), inspired by [haml](http://haml-lang.com/), created by [TJ Holowaychuk](http://github.com/visionmedia)." \
$< > $@
-.PHONY: install uninstall test example
+benchmark:
+ @node benchmarks/jade.js
+
+.PHONY: install uninstall test example benchmark
View
13 benchmark.js
@@ -1,13 +0,0 @@
-
-var jade = require('./lib/jade'),
- str = require('fs').readFileSync(__dirname + '/examples/whitespace.jade', 'utf8'),
- times = 5000;
-
-console.log('rendering ' + times + ' times');
-
-var start = new Date;
-while (times--) {
- jade.render(str);
-}
-
-console.log('took ' + (new Date - start) + 'ms');
View
25 benchmarks/common.js
@@ -0,0 +1,25 @@
+
+var currentLabel,
+ startTime;
+
+exports.times = 5000;
+
+exports.start = function(label){
+ currentLabel = label;
+ startTime = new Date;
+};
+
+exports.stop = function(){
+ var stopTime = new Date,
+ duration = stopTime - startTime;
+ console.log('%s: %dms', currentLabel, duration);
+};
+
+exports.locals = {
+ one: 'one',
+ two: 'two',
+ three: 'three',
+ items: ['foo', 'bar', 'baz', 'raz']
+};
+
+console.log('benchmarking %d times', exports.times);
View
6 benchmarks/example.jade
@@ -0,0 +1,6 @@
+ul
+ li!= one
+ li!= two
+ li!= three
+ - each item in items
+ li!= item
View
32 benchmarks/jade.js
@@ -0,0 +1,32 @@
+
+/**
+ * Module dependencies.
+ */
+
+var bm = require('./common'),
+ jade = require('../lib/jade'),
+ fs = require('fs');
+
+var str = fs.readFileSync(__dirname + '/example.jade', 'ascii');
+var n = bm.times;
+
+bm.start('jade parser');
+while (n--) {
+ jade.render(str, {
+ filename: 'example.jade',
+ locals: bm.locals
+ });
+}
+bm.stop();
+
+var n = bm.times;
+
+bm.start('jade execution');
+while (n--) {
+ jade.render(str, {
+ filename: 'example.jade',
+ cache: true,
+ locals: bm.locals
+ });
+}
+bm.stop();
Please sign in to comment.
Something went wrong with that request. Please try again.