Skip to content

Commit

Permalink
Feature: ability to run individual benchmark
Browse files Browse the repository at this point in the history
Pass env.only argument to webpack to build only the needed benchmark
  • Loading branch information
ksashikumar committed Feb 12, 2018
1 parent 5442220 commit f16e437
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 19 deletions.
43 changes: 25 additions & 18 deletions src/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,33 @@ const defaultOptions = {
minSamples: 20
};

const targetList = [
"acorn",
"babel",
"babylon",
"buble",
"chai",
"coffeescript",
"espree",
"esprima",
"jshint",
"lebab",
"prepack",
"prettier",
"source-map",
"typescript",
"uglify-es",
"uglify-js"
];

const suite = new Benchmark.Suite();
const targetItems = ONLY ? [ONLY] : null;

const requireList = (targetItems || targetList).map(val => {
return require(`./${val}-benchmark`);
});

[
require("./acorn-benchmark"),
require("./babel-benchmark"),
require("./babylon-benchmark"),
require("./buble-benchmark"),
require("./chai-benchmark"),
require("./coffeescript-benchmark"),
require("./espree-benchmark"),
require("./esprima-benchmark"),
require("./jshint-benchmark"),
require("./lebab-benchmark"),
require("./prepack-benchmark"),
require("./prettier-benchmark"),
require("./source-map-benchmark"),
require("./typescript-benchmark"),
require("./uglify-es-benchmark"),
require("./uglify-js-benchmark")
].forEach(options => {
requireList.forEach(options => {
suite.add(Object.assign({}, options, defaultOptions));
});

Expand Down
37 changes: 36 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,36 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const webpack = require("webpack");

module.exports = [
const targetList = [
"acorn",
"babel",
"babylon",
"buble",
"chai",
"coffeescript",
"espree",
"esprima",
"jshint",
"lebab",
"prepack",
"prettier",
"source-map",
"typescript",
"uglify-es",
"uglify-js"
];

function getTarget(env) {
return (
env &&
env.only &&
targetList.find(elem => {
return elem == env.only;
})
);
}

module.exports = env => [
{
context: path.resolve("src"),
entry: "./cli.js",
Expand All @@ -31,6 +60,9 @@ module.exports = [
" console = {log: print};\n" +
"}",
raw: true
}),
new webpack.DefinePlugin({
ONLY: JSON.stringify(getTarget(env))
})
]
},
Expand Down Expand Up @@ -61,6 +93,9 @@ module.exports = [
new HtmlWebpackPlugin({
template: "./index.html",
inject: "head"
}),
new webpack.DefinePlugin({
ONLY: JSON.stringify(getTarget(env))
})
]
}
Expand Down

0 comments on commit f16e437

Please sign in to comment.