eslint-rule-benchmark
Version:
Benchmark ESLint rules with detailed performance metrics for CI and plugin development
54 lines (53 loc) • 1.71 kB
JavaScript
import { collectSystemInfo } from './collect-system-info.js'
import { formatDeviation } from './format-deviation.js'
import { formatMs } from './format-ms.js'
async function useJsonReport(results, _userConfig) {
let systemInfo = await collectSystemInfo()
let testSpecifications = results.map(mapTestSpecResultToJsonReport)
let report = {
testSpecifications,
systemInfo,
}
return JSON.stringify(report, null, 2)
}
function mapTestSpecResultToJsonReport(testSpecResult) {
let testCasesReport = testSpecResult.testCaseResults.map(testCase => {
let samplesReport = testCase.samplesResults.map(sample => {
let sampleName = sample.name.replace(`${testCase.name} on `, '')
return {
metrics: mapMetricsToJson(sample.metrics),
sampleName,
}
})
return {
ruleOptions: testCase.rule.options,
description: testCase.description,
ruleId: testCase.rule.ruleId,
samples: samplesReport,
name: testCase.name,
id: testCase.id,
}
})
return {
benchmarkConfig: testSpecResult.benchmarkConfig,
rulePath: testSpecResult.rulePath,
ruleId: testSpecResult.ruleId,
testCases: testCasesReport,
name: testSpecResult.name,
}
}
function mapMetricsToJson(metrics) {
return {
standardDeviation: formatDeviation(metrics.stdDev),
operationsPerSecond: Math.round(metrics.hz),
medianTime: formatMs(metrics.median),
averageTime: formatMs(metrics.mean),
minimumTime: formatMs(metrics.min),
maximumTime: formatMs(metrics.max),
totalSamples: metrics.sampleCount,
periodInSeconds: metrics.period,
p75: formatMs(metrics.p75),
p99: formatMs(metrics.p99),
}
}
export { useJsonReport }