karma-benchmark-json-reporter
v1.0.1
Published
A reporter for karma-benchmark outputting results to a JSON file
Downloads
119
Maintainers
Readme
karma-benchmark-json-reporter
A reporter for karma-benchmark outputting results to a JSON file.
Install
npm install karma-benchmark-json-reporter
Setting up
After installing karma
, karma-benchmark and your favorite
launcher, in your karma.conf.js
:
module.exports = function (config) {
config.set({
frameworks: ['benchmark'],
reporters: ['benchmark-json'],
// other karma options
// options for 'karma-benchmark-json-reporter'
benchmarkJsonReporter: {
pathToJson: 'my-benchmark-results.json'
}
})
}
See complete working examples for more details.
API
The benchmarkJsonReporter
option container has three settings:
pathToJson
String or array of strings corresponding to the path(s) from the karma basePath
of the output JSON file(s).
Default: results.json
from the karma basePath
.
By setting pathToJson
to an array of paths and customizing formatOutput
, one
can generate multiple output files. See this example for more.
formatResults
Function that takes in the compiled results array and is expected to return an
object that is passed to formatOutput
.
Default: the identity function.
Each compiled results item corresponds to one benchmark run has the following keys:
fullName
: full (and unique) run name concatenatingbrowser
,suite
andname
valuesbrowser
: name of browser usedsuite
: name of suite (as set insuite('<>', function () {}
)name
: name of benchmark (as set inbenchmark('<>', function () {}
)count
: number of times the test was executedcycles
: number of cycles performed while benchmarkinghz
: number of operations per secondhzDeviation
: standard deviation in hzmean
: mean in secondsdeviation
: standard deviation in secondsvariance
: variance in seconds^2moe
: margin of errorrme
: relative margin of error (in percentage of the mean)sem
: standard error of the meansample
: list of sample points
Note that the compiled results are sorted from fastest to slowest hz
values
before being passed to formatResults
.
formatOutput
Function that takes the output of formatResults
and is expected to return a
JSON-serializable object that will be written in the output file(s).
Defaults: function (results) { return { results: results } }
.
If formatOutput
returns an array, then items in the array will be written in
separate JSON files in the same order as the given pathToJson
array setting.
Otherwise, the formatOutput
return value gets JSON stringified into a single
JSON file located at pathToJson
.
Credits
2018 Étienne Tétreault-Pinard. MIT License