benchmark.js
2.22 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Module dependencies.
*/
var uubench = require('uubench')
, pug = require('../');
var suite = new uubench.Suite({
min: 200,
result: function(name, stats){
var persec = 1000 / stats.elapsed
, ops = stats.iterations * persec;
console.log('%s: %d', name, ops | 0);
}
});
function setup(self) {
var suffix = self ? ' (self)' : ''
, options = { self: self };
var str = 'html\n body\n h1 Title'
, fn = pug.compile(str, options);
suite.bench('tiny' + suffix, function(next){
fn();
next();
});
str = '\
html\n\
body\n\
h1 Title\n\
ul#menu\n\
li: a(href="#") Home\n\
li: a(href="#") About Us\n\
li: a(href="#") Store\n\
li: a(href="#") FAQ\n\
li: a(href="#") Contact\n\
';
var fn2 = pug.compile(str, options);
suite.bench('small' + suffix, function(next){
fn2();
next();
});
str = '\
html\n\
body\n\
h1 #{title}\n\
ul#menu\n\
- each link in links\r\n\
li: a(href="#")= link\r\n\
';
if (self) {
str = '\
html\n\
body\n\
h1 #{self.title}\n\
ul#menu\n\
- each link in self.links\r\n\
li: a(href="#")= link\r\n\
';
}
var fn3 = pug.compile(str, options);
suite.bench('small locals' + suffix, function(next){
fn3({ title: 'Title', links: ['Home', 'About Us', 'Store', 'FAQ', 'Contact'] });
next();
});
str = '\
html\n\
body\n\
h1 Title\n\
ul#menu\n\
li: a(href="#") Home\n\
li: a(href="#") About Us\n\
li: a(href="#") Store\n\
li: a(href="#") FAQ\n\
li: a(href="#") Contact\n\
';
str = Array(30).join(str);
var fn4 = pug.compile(str, options);
suite.bench('medium' + suffix, function(next){
fn4();
next();
});
str = '\
html\n\
body\n\
h1 Title\n\
ul#menu\n\
li: a(href="#") Home\n\
li: a(href="#") About Us\n\
li: a(href="#") Store\n\
li: a(href="#") FAQ\n\
li: a(href="#") Contact\n\
';
str = Array(100).join(str);
var fn5 = pug.compile(str, options);
suite.bench('large' + suffix, function(next){
fn5();
next();
});
}
setup();
setup(true);
suite.run();