From f16e437854e789b6d5b4493f8180f5620995bd6d Mon Sep 17 00:00:00 2001 From: K Sashi Kumar Date: Mon, 12 Feb 2018 11:11:08 +0530 Subject: [PATCH] Feature: ability to run individual benchmark Pass env.only argument to webpack to build only the needed benchmark --- src/suite.js | 43 +++++++++++++++++++++++++------------------ webpack.config.js | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/src/suite.js b/src/suite.js index c3505803..b7a31f05 100644 --- a/src/suite.js +++ b/src/suite.js @@ -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)); }); diff --git a/webpack.config.js b/webpack.config.js index a20fe8b2..af3bd826 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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", @@ -31,6 +60,9 @@ module.exports = [ " console = {log: print};\n" + "}", raw: true + }), + new webpack.DefinePlugin({ + ONLY: JSON.stringify(getTarget(env)) }) ] }, @@ -61,6 +93,9 @@ module.exports = [ new HtmlWebpackPlugin({ template: "./index.html", inject: "head" + }), + new webpack.DefinePlugin({ + ONLY: JSON.stringify(getTarget(env)) }) ] }