Socket
Socket
Sign inDemoInstall

karma-benchmark-json-reporter

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 1.0.0

lib/compile_results.js

122

index.js
var fs = require('fs')
var path = require('path')
var WHITESPACE = /s/g
var fillResultSet = require('./lib/fill_result_set')
var compileResults = require('./lib/compile_results')
var normarlizePath = require('./lib/normalize_path')
var BenchReporter = function (baseReporterDecorator, config) {

@@ -11,3 +13,3 @@ baseReporterDecorator(this)

var opts = config[this._key] || {}
var pathToJson = getPathToJson(config, opts)
var pathToJson = coercePathToJson(config, opts)

@@ -25,8 +27,3 @@ var formatResults = isFunction(opts.formatResults)

this.specSuccess = function (browser, result) {
var browserName = browser.name
var suite = result.benchmark.suite
var browserSet = resultSet[browserName] = resultSet[browserName] || {}
browserSet[suite] = browserSet[suite] || []
browserSet[suite].push(result)
fillResultSet(resultSet, browser, result)
}

@@ -51,107 +48,14 @@

}
this._getPathToJson = getPathToJson
}
function getPathToJson (config, opts) {
function coercePathToJson (config, opts) {
return coerceToArray(opts.pathToJson).map(function (p) {
if (typeof p !== 'string' || p === '') {
return path.join(config.basePath, 'results.json')
} else {
if (path.isAbsolute(p)) {
return p
} else {
return path.join(config.basePath, p)
}
}
return normarlizePath(p, config.basePath, 'results.json')
})
}
function compileResults (resultSet) {
var runs = []
var caseNames = []
Object.keys(resultSet).forEach(function (browserName) {
var browserSet = resultSet[browserName]
Object.keys(browserSet).forEach(function (suiteName) {
var results = browserSet[suiteName]
results.forEach(function (result) {
var benchmark = result.benchmark
var benchmarkName = benchmark.name
var benchmarkStats = benchmark.stats
var caseName = [
suiteName.replace(WHITESPACE, '-'),
benchmarkName.replace(WHITESPACE, '-'),
browserName.replace(WHITESPACE, '-')
].join('-')
if (caseNames.indexOf(caseName) !== -1) {
console.warn('Same benchmark done twice', caseName)
}
caseNames.push(caseName)
runs.push({
fullName: caseName,
browser: browserName,
suite: suiteName,
name: benchmarkName,
// number of times the test was executed
count: benchmark.count,
// number of cycles performed while benchmarking
cycles: benchmark.cycles,
// number of operations per sec
hz: benchmark.hz,
// standard deviation in hz
hzDeviation: calcHzDeviation(benchmarkStats),
// mean in secs
mean: benchmarkStats.mean,
// standard deviation in secs
deviation: benchmarkStats.deviation,
// variance in secs^2
variance: benchmarkStats.variance,
// margin of error
moe: benchmarkStats.moe,
// relative margin of error (in percentage of the mean)
rme: benchmarkStats.rme,
// standard error of the mean
sem: benchmarkStats.sem,
// list of sample points
sample: benchmarkStats.sample
})
})
})
})
// sort from fastest to slowest
runs.sort(function (a, b) {
return b.hz - a.hz
})
return runs
function coerceToArray (input) {
return Array.isArray(input) ? input : [input]
}
function calcHzDeviation (stats) {
var sample = stats.sample
var N = sample.length
var sum = 0
for (var i = 0; i < N; i++) {
sum += 1 / sample[i]
}
var mean = sum / (N - 1)
var ssq = 0
for (var j = 0; j < N; j++) {
ssq += Math.pow((1 / sample[j]) - mean, 2)
}
return Math.sqrt(ssq / (N - 1))
}
function isFunction (obj) {

@@ -161,8 +65,2 @@ return typeof obj === 'function'

function coerceToArray (input) {
return Array.isArray(input)
? input
: [input]
}
BenchReporter.$inject = ['baseReporterDecorator', 'config']

@@ -169,0 +67,0 @@

{
"name": "karma-benchmark-json-reporter",
"version": "0.2.0",
"version": "1.0.0",
"description": "A reporter for karma-benchmark outputting results to a JSON file",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -42,3 +42,3 @@ # karma-benchmark-json-reporter

See complete [examples][example].
See complete working [examples][example] for more details.

@@ -57,3 +57,3 @@ ## API

By setting `pathToJson` to an array of paths and customizing `formatOutput`, one
can generate multiple output files. See [example][example-02].
can generate multiple output files. See this [example][example-02] for more.

@@ -76,7 +76,7 @@ ### `formatResults`

- `cycles`: number of cycles performed while benchmarking
- `hz`: number of operations per sec
- `hz`: number of operations per second
- `hzDeviation`: standard deviation in hz
- `mean`: mean in secs benchmarkStats.mean,
- `deviation`: standard deviation in secs
- `variance`: variance in secs^2
- `mean`: mean in seconds
- `deviation`: standard deviation in seconds
- `variance`: variance in seconds^2
- `moe`: margin of error

@@ -83,0 +83,0 @@ - `rme`: relative margin of error (in percentage of the mean)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc