A configurable Karma reporter for the karma-benchmark plugin.
npm install karma-benchmark karma-benchmarkjs-reporter --save-dev
Add benchmark
to your frameworks
and reporters
arrays. Optionally, specify a benchmarkReporter
config object:
module.exports = function(config) {
config.set({
// ...
frameworks: ["benchmark"],
reporters: ["benchmark"],
// optional configuration object :
benchmarkReporter: {
colors: config.colors,
style: style,
decorator: "-",
terminalWidth: 60,
hzWidth: 4,
hzUnits: "ops/sec",
browserWidth: 40,
showBrowser: false,
showSuiteSummary: false,
formatBenchmark: formatBenchmark,
formatSuiteHeading: formatSuiteHeading,
formatSuiteSummary: formatSuiteSummary
}
});
};
default: true
This value is inherited from Karma, but you can override it by specifying a boolean.
default:
{
benchmark: chalk.stripColor,
summaryBenchmark: chalk.underline,
summaryEmphasis: chalk.bold.underline,
browser: chalk.blue,
decorator: chalk.cyan,
hz: chalk.green,
hzUnits: chalk.italic.dim,
suite: chalk.bold.magenta
}
The style object contains the styling functions for each piece of data. The default uses chalk
for styling and color.
default: "-"
The decorator for the beginning of each benchmark row.
default: 60
The default formatting functions attempt to match this column width for each row. There is still possibility for overflow.
default: 4
The default formatting functions use this to pad the formatted hz
string.
default: "ops/sec"
The string placed after the hz
as units.
default: 40
The default formatting functions use this to pad the browser name.
default: false
The default formatting functions only output the browser name if set to true
. It is useful if you are benchmarking multiple browsers.
default: false
Specify if you want to call the formatSuiteSummary
function at the end of a suite.
If you override the default formatting functions, you must ensure that your functions take into account the other configuration values (if you want to use them).
View the default formatting functions
/**
* @param {Object} benchmark the benchmark to be formatted
* @param {Object} browser the browser associated with the benchmark
* @param {Object} benchConfig the benchmarkReporter config obj
* @return {string} the formatted benchmark
*/
var formatBenchmark = function (benchmark, browser, benchConfig) {...};
/**
* @param {string} suiteName name of performance suite
* @param {Object} browser browser object
* @param {Object} benchConfig benchmarkReporter config object
* @return {string} formatted suite heading
*/
var formatSuiteHeading = function (suiteName, browser, benchConfig) {...};
/**
* @param {Object[]} suite array of browserBenchmarks: `{browser: {Obj}, benchmark: {Obj}`
* @param {Object} benchConfig benchmarkReporter config obj
* @return {string} the formatted suite summary
*/
var formatSuiteSummary = function (suite, benchConfig) {