forked from sweet-js/sweet-core
/
test_benchmark.js
67 lines (51 loc) · 1.36 KB
/
test_benchmark.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
59
60
61
62
63
64
65
66
67
var parser = require("./lib/parser");
var expander = require("./lib/expander");
var sweet = require("./lib/sweet");
var Benchmark = require("benchmark");
var suite = new Benchmark.Suite;
function dup(code, n) {
var tmp = "";
for(var i = 0; i < n; i++) {
tmp += code;
}
return tmp;
}
var MAX = 25;
var identDeclCode = {};
var identCode = {}
function stepBy(start, by, max, f) {
for(var i = start; i <= max; i += by) {
f(i);
}
}
suite.add("(expand) empty string", function() {
var stx = parser.read("");
var res = expander.expand(stx);
})
stepBy(0, 5, MAX, function(i) {
identDeclCode[i] = dup("var x;", i);
identCode[i] = dup("x + 2;", i);
suite.add("(expand) simple idents - " + i, function() {
var stx = parser.read(identCode[i]);
var res = expander.expand(stx);
});
});
stepBy(0, 5, MAX, function(i) {
suite.add("(expand+parse) simple idents - " + i, function() {
var res = sweet.parse(identCode[i]);
});
});
stepBy(0, 5, MAX, function(i) {
suite.add("(expand) var idents - " + i, function() {
var stx = parser.read(identDeclCode[i]);
var res = expander.expand(stx);
});
});
stepBy(0, 5, MAX, function(i) {
suite.add("(expand+parse) var idents - " + i, function() {
var res = sweet.parse(identDeclCode[i]);
});
});
suite.on('cycle', function(event) {
console.log(String(event.target));
}).run({'async': true});