Merge pull request #7522 from byzyk/fix/benchmark

chore(benchmark): add folder to ESLint
This commit is contained in:
Tobias Koppers 2018-06-20 10:55:58 +02:00 committed by GitHub
commit a1e79ab816
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 222 additions and 175 deletions

View File

@ -7,6 +7,7 @@
!bin/*.js
!hot/*.js
!buildin/*.js
!benchmark/**/*.js
!test/*.js
!test/**/webpack.config.js
!examples/**/webpack.config.js

View File

@ -14,13 +14,15 @@ const benchmarkOptions = {
};
function runTimes(compiler, times, deferred) {
fs.writeFileSync(path.join(fixtures, "0.js"), "module.exports = " + Math.random(), "utf-8");
fs.writeFileSync(
path.join(fixtures, "0.js"),
"module.exports = " + Math.random(),
"utf-8"
);
compiler.run(err => {
if(err) throw err;
if(times === 1)
deferred.resolve();
else
runTimes(compiler, times - 1, deferred);
if (err) throw err;
if (times === 1) deferred.resolve();
else runTimes(compiler, times - 1, deferred);
});
}
@ -28,103 +30,102 @@ const tests = {
"normal build": [
[0, 1, 5, 10, 50, 100, 200],
(size, deferred) => {
webpack({
context: fixtures,
entry: `./${size}.js`,
output: {
path: outputPath,
filename: "bundle.js"
webpack(
{
context: fixtures,
entry: `./${size}.js`,
output: {
path: outputPath,
filename: "bundle.js"
}
},
err => {
if (err) throw err;
deferred.resolve();
}
}, err => {
if(err) throw err;
deferred.resolve();
});
);
}
],
"eval dev build": [
[0, 1, 2, 5, 10, 15],
(size, deferred) => {
webpack({
context: fixtures,
entry: `./${size}.big.js`,
output: {
path: outputPath,
filename: "bundle.js"
webpack(
{
context: fixtures,
entry: `./${size}.big.js`,
output: {
path: outputPath,
filename: "bundle.js"
},
devtool: "eval"
},
devtool: "eval"
}, err => {
if(err) throw err;
deferred.resolve();
});
err => {
if (err) throw err;
deferred.resolve();
}
);
}
],
"sourcemap build": [
[0, 1, 2, 5, 10, 15],
(size, deferred) => {
webpack({
context: fixtures,
entry: `./${size}.big.js`,
output: {
path: outputPath,
filename: "bundle.js"
webpack(
{
context: fixtures,
entry: `./${size}.big.js`,
output: {
path: outputPath,
filename: "bundle.js"
},
devtool: "source-map"
},
devtool: "source-map"
}, err => {
if(err) throw err;
deferred.resolve();
});
err => {
if (err) throw err;
deferred.resolve();
}
);
}
],
"cheap sourcemap build": [
[0, 1, 2, 5, 10, 15],
(size, deferred) => {
webpack({
context: fixtures,
entry: `./${size}.big.js`,
output: {
path: outputPath,
filename: "bundle.js"
webpack(
{
context: fixtures,
entry: `./${size}.big.js`,
output: {
path: outputPath,
filename: "bundle.js"
},
devtool: "cheap-source-map"
},
devtool: "cheap-source-map"
}, err => {
if(err) throw err;
deferred.resolve();
});
err => {
if (err) throw err;
deferred.resolve();
}
);
}
],
"build w/ chunks": [
[0, 1, 5, 10, 50, 100, 200],
(size, deferred) => {
webpack({
context: fixtures,
entry: `./${size}.async.js`,
output: {
path: outputPath,
filename: "bundle.js"
webpack(
{
context: fixtures,
entry: `./${size}.async.js`,
output: {
path: outputPath,
filename: "bundle.js"
}
},
err => {
if (err) throw err;
deferred.resolve();
}
}, err => {
if(err) throw err;
deferred.resolve();
});
);
}
],
"build w/ chunks": [
[0, 1, 5, 10, 50, 100, 200],
(size, deferred) => {
webpack({
context: fixtures,
entry: "./" + size + ".async.js",
output: {
path: outputPath,
filename: "bundle.js"
}
}, err => {
if(err) throw err;
deferred.resolve();
});
}
],
"incremental": [
incremental: [
[0, 1, 5, 10, 50, 100, 200],
(size, deferred) => {
var compiler = webpack({
@ -155,7 +156,7 @@ const tests = {
runTimes(compiler, size, deferred);
}
],
"incremental2": [
incremental2: [
[0, 1, 5, 10, 50, 100, 200],
(size, deferred) => {
var compiler = webpack({
@ -170,7 +171,7 @@ const tests = {
runTimes(compiler, 3, deferred);
}
],
"incremental4": [
incremental4: [
[0, 1, 5, 10, 50, 100, 200],
(size, deferred) => {
var compiler = webpack({
@ -185,7 +186,7 @@ const tests = {
runTimes(compiler, 5, deferred);
}
],
"incremental16": [
incremental16: [
[0, 1, 5, 10, 50, 100, 200],
(size, deferred) => {
var compiler = webpack({
@ -199,25 +200,38 @@ const tests = {
});
runTimes(compiler, 17, deferred);
}
],
]
};
const suite = new Benchmark.Suite;
const suite = new Benchmark.Suite();
Object.keys(tests).filter(name => process.argv.length > 2 ? name.includes(process.argv[2]) : true)
Object.keys(tests)
.filter(
name => (process.argv.length > 2 ? name.includes(process.argv[2]) : true)
)
.forEach(name => {
const test = tests[name];
test[0].forEach(size => {
suite.add(`${name} ${size}`, deferred => {
test[1](size, deferred);
}, benchmarkOptions);
suite.add(
`${name} ${size}`,
deferred => {
test[1](size, deferred);
},
benchmarkOptions
);
});
});
suite.on("cycle", event => {
process.stderr.write("\n");
const b = event.target;
console.log(b.name + "\t" + Math.floor(1000 * (b.stats.mean - b.stats.moe)) + "\t" + Math.floor(1000 * (b.stats.mean + b.stats.moe)));
console.log(
b.name +
"\t" +
Math.floor(1000 * (b.stats.mean - b.stats.moe)) +
"\t" +
Math.floor(1000 * (b.stats.mean + b.stats.moe))
);
});
suite.run({

View File

@ -1,22 +1,28 @@
const webpack = require("webpack");
const webpack = require("../");
const path = require("path");
webpack({
context: __dirname,
entry: "./createBenchmark/entry.js",
output: {
path: __dirname,
filename: "benchmark-bundle.js"
webpack(
{
context: __dirname,
entry: "./createBenchmark/entry.js",
output: {
path: __dirname,
filename: "benchmark-bundle.js"
},
target: "node",
node: {
__dirname: false
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.IgnorePlugin(/^(fsevents|uglify-js)$/),
new webpack.NormalModuleReplacementPlugin(
/^.\/loadLoader$/,
path.resolve(__dirname, "./createBenchmark/loadLoader")
)
]
},
target: "node",
node: {
__dirname: false
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.IgnorePlugin(/^(fsevents|uglify-js)$/),
new webpack.NormalModuleReplacementPlugin(/^.\/loadLoader$/, path.resolve(__dirname, "./createBenchmark/loadLoader"))
]
}, (err, stats) => {
console.log(stats.toString());
});
(err, stats) => {
console.log(stats.toString());
}
);

View File

@ -1,5 +1,4 @@
const webpack = require("webpack");
const MemoryFs = require("memory-fs");
const webpack = require("../../");
const path = require("path");
const testCase = process.argv[2];
@ -15,11 +14,13 @@ const config = {
const compiler = webpack(config);
compiler.run((err, stats) => {
if(err) {
if (err) {
console.error(err);
} else {
console.log(stats.toString({
errorDetails: true
}));
console.log(
stats.toString({
errorDetails: true
})
);
}
});

View File

@ -1,3 +1,3 @@
module.exports = (loader, callback) => {
callback(new Error("Loaders are not supported"));
}
};

View File

@ -5,55 +5,55 @@ const fixtures = path.join(__dirname, "fixtures");
try {
fs.mkdirSync(fixtures);
} catch(e) {}
} catch (e) {
// The directory already exists
}
function generateRequireString(conditional, suffix) {
const prefixedSuffix = suffix ? `.${suffix}` : "";
return `require(${JSON.stringify(`./${conditional}${prefixedSuffix}.js`)});`;
}
for(let i = 0; i < 10000; i++) {
for (let i = 0; i < 10000; i++) {
const source = [];
if(i > 8)
source.push(generateRequireString((i / 8 | 0)));
if(i > 4)
source.push(generateRequireString((i / 4 | 0)));
if(i > 2)
source.push(generateRequireString((i / 2 | 0)));
if(i > 0)
source.push(generateRequireString((i - 1)));
if (i > 8) source.push(generateRequireString((i / 8) | 0));
if (i > 4) source.push(generateRequireString((i / 4) | 0));
if (i > 2) source.push(generateRequireString((i / 2) | 0));
if (i > 0) source.push(generateRequireString(i - 1));
source.push("module.exports = " + i + ";");
fs.writeFileSync(path.join(fixtures, i + ".js"), source.join("\n"), "utf-8");
}
for(let i = 0; i < 10000; i++) {
for (let i = 0; i < 10000; i++) {
const source = [];
source.push("require.ensure([], function(require) {");
if(i > 8)
source.push(generateRequireString((i / 8 | 0), "async"));
if(i > 4)
source.push(generateRequireString((i / 4 | 0), "async"));
if(i > 2)
source.push(generateRequireString((i / 2 | 0), "async"));
if(i > 0)
source.push(generateRequireString((i - 1), "async"));
if (i > 8) source.push(generateRequireString((i / 8) | 0, "async"));
if (i > 4) source.push(generateRequireString((i / 4) | 0, "async"));
if (i > 2) source.push(generateRequireString((i / 2) | 0, "async"));
if (i > 0) source.push(generateRequireString(i - 1, "async"));
source.push("});");
source.push("module.exports = " + i + ";");
fs.writeFileSync(path.join(fixtures, i + ".async.js"), source.join("\n"), "utf-8");
fs.writeFileSync(
path.join(fixtures, i + ".async.js"),
source.join("\n"),
"utf-8"
);
}
for(let i = 0; i < 100; i++) {
for (let i = 0; i < 100; i++) {
const source = [];
if(i > 8)
source.push(generateRequireString((i / 8 | 0), "big"));
if(i > 4)
source.push(generateRequireString((i / 4 | 0), "big"));
if(i > 2)
source.push(generateRequireString((i / 2 | 0), "big"));
if(i > 0)
source.push(generateRequireString((i - 1), "big"));
for(let j = 0; j < 300; j++)
source.push("if(Math.random())hello.world();test.a.b.c.d();x(1,2,3,4);var a,b,c,d,e,f;");
if (i > 8) source.push(generateRequireString((i / 8) | 0, "big"));
if (i > 4) source.push(generateRequireString((i / 4) | 0, "big"));
if (i > 2) source.push(generateRequireString((i / 2) | 0, "big"));
if (i > 0) source.push(generateRequireString(i - 1, "big"));
for (let j = 0; j < 300; j++)
source.push(
"if(Math.random())hello.world();test.a.b.c.d();x(1,2,3,4);var a,b,c,d,e,f;"
);
source.push("module.exports = " + i + ";");
fs.writeFileSync(path.join(fixtures, i + ".big.js"), source.join("\n"), "utf-8");
fs.writeFileSync(
path.join(fixtures, i + ".big.js"),
source.join("\n"),
"utf-8"
);
}

View File

@ -5,45 +5,57 @@ const fixtures = path.join(__dirname, "fixtures");
try {
fs.mkdirSync(fixtures);
} catch(e) {}
} catch (e) {
// The directory already exists
}
function genModule(prefix, depth, asyncDepth, multiplex, r, circular) {
const source = [];
const isAsync = depth >= asyncDepth;
if(!isAsync)
circular.push(path.resolve(fixtures, prefix + "/index.js"));
if (!isAsync) circular.push(path.resolve(fixtures, prefix + "/index.js"));
source.push("(function() {");
const m = (r % multiplex) + 1;
let sum = 1;
let item;
try {
fs.mkdirSync(path.resolve(fixtures, prefix));
} catch(e) {}
if(depth > 0) {
for(let i = 0; i < m; i++) {
sum += genModule(prefix + "/" + i, depth - 1, asyncDepth, multiplex, (r + i + depth) * m + i + depth, circular);
} catch (e) {
// The directory already exists
}
if (depth > 0) {
for (let i = 0; i < m; i++) {
sum += genModule(
prefix + "/" + i,
depth - 1,
asyncDepth,
multiplex,
(r + i + depth) * m + i + depth,
circular
);
source.push("require(" + JSON.stringify("./" + i) + ");");
if(i === 0) {
if(isAsync)
source.push("}); require.ensure([], function() {");
if (i === 0) {
if (isAsync) source.push("}); require.ensure([], function() {");
}
}
item = circular[r % circular.length];
}
source.push("}, " + JSON.stringify(prefix) + ");");
if(item)
source.push("require(" + JSON.stringify(item) + ");");
if (item) source.push("require(" + JSON.stringify(item) + ");");
source.push("module.exports = " + JSON.stringify(prefix) + ";");
fs.writeFileSync(path.resolve(fixtures, prefix + "/index.js"), source.join("\n"), "utf-8");
fs.writeFileSync(
path.resolve(fixtures, prefix + "/index.js"),
source.join("\n"),
"utf-8"
);
return sum;
}
for(let i = 2; i < 14; i++) {
for (let i = 2; i < 14; i++) {
const count = genModule("tree-" + i, 6, 100, i, 0, []);
console.log("generated tree", i, count);
}
for(let i = 2; i < 14; i++) {
for (let i = 2; i < 14; i++) {
const count = genModule("async-tree-" + i, 6, 1, i, 0, []);
console.log("generated async tree", i, count);
}

View File

@ -30,9 +30,9 @@ function c() {}
function d() {}
function e() {}
function f() {}
`
`;
for(let i = 0; i < 2; i++) {
for (let i = 0; i < 2; i++) {
avgJs += `(function() {${avgJs}}());`;
}
@ -50,20 +50,33 @@ function createTree(fs, count, folder) {
let remaining = count - 1;
function make(prefix, count, depth) {
if(count === 0) {
if (count === 0) {
fs.writeFileSync(`${folder}/${prefix}.js`, `export default 1;\n${avgJs}`);
} else {
const list = [];
for(let i = 0; i < count; i++) {
if(remaining-- <= 0) break;
if(depth <= 4 && i >= 3 && i <= 4) {
list.push(`const module${i} = import("./${prefix}-${i}");\ncounter += module${i};`);
for (let i = 0; i < count; i++) {
if (remaining-- <= 0) break;
if (depth <= 4 && i >= 3 && i <= 4) {
list.push(
`const module${i} = import("./${prefix}-${i}");\ncounter += module${i};`
);
} else {
list.push(`import module${i} from "./${prefix}-${i}";\ncounter += module${i};`);
list.push(
`import module${i} from "./${prefix}-${i}";\ncounter += module${i};`
);
}
make(`${prefix}-${i}`, depth > 4 || count > 30 ? 0 : count + depth + i ** 2, depth + 1);
make(
`${prefix}-${i}`,
depth > 4 || count > 30 ? 0 : count + depth + Math.pow(i, 2),
depth + 1
);
}
fs.writeFileSync(`${folder}/${prefix}.js`, `let counter = 0;\n${list.join("\n")};\nexport default counter;\n${avgJs}`)
fs.writeFileSync(
`${folder}/${prefix}.js`,
`let counter = 0;\n${list.join(
"\n"
)};\nexport default counter;\n${avgJs}`
);
}
}
make("index", 2, 0);

View File

@ -60,7 +60,7 @@
"less": "^2.5.1",
"less-loader": "^4.0.3",
"lodash": "^4.17.4",
"prettier": "^1.13.2",
"prettier": "^1.13.5",
"pug": "^2.0.3",
"pug-loader": "^2.4.0",
"raw-loader": "~0.5.0",
@ -118,10 +118,10 @@
"pretest": "yarn lint",
"prelint": "yarn setup",
"lint": "yarn code-lint && yarn schema-lint && yarn type-lint",
"code-lint": "eslint --cache setup lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"",
"code-lint": "eslint --cache setup lib bin hot buildin benchmark \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\"",
"type-lint": "tsc --pretty",
"fix": "yarn code-lint --fix",
"pretty": "prettier --write \"setup/**/*.js\" \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\" \"declarations.d.ts\"",
"pretty": "prettier --write \"setup/**/*.js\" \"lib/**/*.js\" \"bin/*.js\" \"hot/*.js\" \"buildin/*.js\" \"benchmark/**/*.js\" \"test/*.js\" \"test/**/webpack.config.js\" \"examples/**/webpack.config.js\" \"schemas/**/*.js\" \"declarations.d.ts\"",
"schema-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.lint.js\" --no-verbose",
"benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.benchmark.js\" --runInBand",
"cover": "yarn cover:init && yarn cover:all && yarn cover:report",

View File

@ -4700,9 +4700,9 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
prettier@^1.13.2:
version "1.13.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.2.tgz#412b87bc561cb11074d2877a33a38f78c2303cda"
prettier@^1.13.5:
version "1.13.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.5.tgz#7ae2076998c8edce79d63834e9b7b09fead6bfd0"
pretty-format@^23.0.1:
version "23.0.1"