-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
run.js
executable file
·60 lines (45 loc) · 1.19 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
/**
* Module dependencies.
*/
var sys = require('sys'),
fs = require('fs'),
jade = require('./../lib/jade'),
haml = require('./haml/lib/haml');
/**
* Iterations.
*/
var times = 500;
sys.puts('running ' + times + ' times.');
/**
* Run benchmarks,
*
* @param {String} label
* @param {Function} fn
*/
function bm(label, fn) {
var n = times,
start = +new Date,
dotAt = times / 10;
while (n--) {
if (n % dotAt === 0) sys.print('.');
fn();
}
sys.puts(' ' + label + ': \x1b[32m' + (+new Date - start) + '\x1b[0m ms');
}
// Setup
var jadeStr = fs.readFileSync(__dirname + '/layout.jade', 'utf8');
var hamlStr = fs.readFileSync(__dirname + '/layout.haml', 'utf8');
// Benchmarks
bm('jade render', function(){
jade.render(jadeStr, { locals: { title: 'Jade' }});
});
bm('haml.js render', function(){
haml.render(hamlStr, { locals: { title: 'Haml' }});
});
bm('jade cached', function(){
jade.render(jadeStr, { cache: true, filename: 'layout.jade', locals: { title: 'Jade' }});
});
bm('haml.js cached', function(){
haml.render(hamlStr, { cache: true, filename: 'layout.haml', locals: { title: 'Haml' }});
});