Skip to content

Commit 04fcde9

Browse files
committed
add files to create a benchmark bundle and test cases
1 parent ab7bac8 commit 04fcde9

4 files changed

Lines changed: 119 additions & 0 deletions

File tree

benchmark/createBenchmark.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const webpack = require("webpack");
2+
const path = require("path");
3+
4+
webpack({
5+
context: __dirname,
6+
entry: "./createBenchmark/entry.js",
7+
output: {
8+
path: __dirname,
9+
filename: "benchmark-bundle.js"
10+
},
11+
target: "node",
12+
node: {
13+
__dirname: false
14+
},
15+
plugins: [
16+
new webpack.NamedModulesPlugin(),
17+
new webpack.IgnorePlugin(/^(fsevents|uglify-js)$/),
18+
new webpack.NormalModuleReplacementPlugin(/^.\/loadLoader$/, path.resolve(__dirname, "./createBenchmark/loadLoader"))
19+
]
20+
}, function(err, stats) {
21+
console.log(stats.toString());
22+
});

benchmark/createBenchmark/entry.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const webpack = require("webpack");
2+
const MemoryFs = require("memory-fs");
3+
const path = require("path");
4+
5+
const testCase = process.argv[2];
6+
7+
const config = {
8+
context: __dirname,
9+
entry: `./${testCase}`,
10+
output: {
11+
path: path.resolve(__dirname, "output-" + testCase)
12+
},
13+
devtool: process.argv[3]
14+
};
15+
16+
const compiler = webpack(config);
17+
compiler.run((err, stats) => {
18+
if(err) {
19+
console.error(err);
20+
} else {
21+
console.log(stats.toString({
22+
errorDetails: true
23+
}));
24+
}
25+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (loader, callback) => {
2+
callback(new Error("Loaders are not supported"));
3+
}

benchmark/createTestCases.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
let avgJs = `
2+
const str = "we" + "do" + "some" + "ops";
3+
for(const x of str.split("")) {
4+
if(x.charCodeAt(0) > 40) {
5+
console.log("omg");
6+
} else {
7+
console.log(Math.random() * 2 + 3 * 2);
8+
}
9+
}
10+
11+
// Some comment
12+
switch(a.b.c.d.f.e.g.h.i) {
13+
case true:
14+
break;
15+
case "magic":
16+
throw new Error("Error!");
17+
case 9:
18+
(function() {
19+
// extra scope
20+
var x = 123;
21+
var y = 456;
22+
var z = x + z * x / y;
23+
x && y && (z = x ? y : x);
24+
}())
25+
}
26+
27+
function a() {}
28+
function b() {}
29+
function c() {}
30+
function d() {}
31+
function e() {}
32+
function f() {}
33+
`
34+
35+
for(var i = 0; i < 2; i++) {
36+
avgJs += `(function() {${avgJs}}());`;
37+
}
38+
39+
const fs = require("fs");
40+
const root = __dirname;
41+
42+
createTree(fs, 100, `${root}/modules-100`);
43+
createTree(fs, 500, `${root}/modules-500`);
44+
createTree(fs, 1000, `${root}/modules-1000`);
45+
createTree(fs, 3000, `${root}/modules-3000`);
46+
createTree(fs, 5000, `${root}/modules-5000`);
47+
48+
function createTree(fs, count, folder) {
49+
fs.mkdirSync(folder);
50+
let remaining = count - 1;
51+
function make(prefix, count, depth) {
52+
if(count === 0) {
53+
fs.writeFileSync(`${folder}/${prefix}.js`, `export default 1;\n${avgJs}`);
54+
} else {
55+
const list = [];
56+
for(let i = 0; i < count; i++) {
57+
if(remaining-- <= 0) break;
58+
if(depth <= 4 && i >= 3 && i <= 4) {
59+
list.push(`const module${i} = import("./${prefix}-${i}");\ncounter += module${i};`);
60+
} else {
61+
list.push(`import module${i} from "./${prefix}-${i}";\ncounter += module${i};`);
62+
}
63+
make(`${prefix}-${i}`, depth > 4 || count > 30 ? 0 : count + depth + i ** 2, depth + 1);
64+
}
65+
fs.writeFileSync(`${folder}/${prefix}.js`, `let counter = 0;\n${list.join("\n")};\nexport default counter;\n${avgJs}`)
66+
}
67+
}
68+
make("index", 2, 0);
69+
}

0 commit comments

Comments
 (0)