Skip to content

Commit 4c2ae56

Browse files
committed
added more benchmark fixtures
1 parent ca8b693 commit 4c2ae56

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎benchmark/createFixtures2.js‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var path = require("path");
2+
var fs = require("fs");
3+
4+
var fixtures = path.join(__dirname, "fixtures");
5+
6+
try {
7+
fs.mkdirSync(fixtures);
8+
} catch(e) {}
9+
10+
function genModule(prefix, depth, asyncDepth, multiplex, r, circular) {
11+
var source = [];
12+
var async = depth >= asyncDepth;
13+
if(!async)
14+
circular.push(path.resolve(fixtures, prefix + "/index.js"));
15+
source.push("(function() {");
16+
var m = (r % multiplex) + 1;
17+
var sum = 1;
18+
try {
19+
fs.mkdirSync(path.resolve(fixtures, prefix));
20+
} catch(e) {}
21+
if(depth > 0) {
22+
for(var i = 0; i < m; i++) {
23+
sum += genModule(prefix + "/" + i, depth - 1, asyncDepth, multiplex, (r + i + depth) * m + i + depth, circular);
24+
source.push("require(" + JSON.stringify("./" + i) + ");");
25+
if(i === 0) {
26+
if(async)
27+
source.push("}); require.ensure([], function() {");
28+
}
29+
}
30+
var item = circular[r % circular.length];
31+
}
32+
source.push("}, " + JSON.stringify(prefix) + ");");
33+
if(item)
34+
source.push("require(" + JSON.stringify(item) + ");");
35+
source.push("module.exports = " + JSON.stringify(prefix) + ";");
36+
fs.writeFileSync(path.resolve(fixtures, prefix + "/index.js"), source.join("\n"), "utf-8");
37+
return sum;
38+
}
39+
40+
for(var i = 2; i < 14; i++) {
41+
var count = genModule("tree-" + i, 6, 100, i, 0, []);
42+
console.log("generated tree", i, count);
43+
}
44+
45+
for(var i = 2; i < 14; i++) {
46+
var count = genModule("async-tree-" + i, 6, 1, i, 0, []);
47+
console.log("generated async tree", i, count);
48+
}
49+
50+
var a = genModule("module-async", 7, 1, 3, 2, []);
51+
52+
var b = genModule("module-big-async", 5, 2, 9, 2, []);
53+
54+
var c = genModule("module-broad-async", 3, 3, 20, 10, []);
55+
56+
console.log("generated modules", a, b, c);

0 commit comments

Comments
 (0)