eslint-rule-benchmark
Version:
Benchmark ESLint rules with detailed performance metrics for CI and plugin development
82 lines (81 loc) • 2.77 kB
JavaScript
import { collectSystemInfo } from './collect-system-info.js'
import { formatDeviation } from './format-deviation.js'
import { formatMs } from './format-ms.js'
import { formatHz } from './format-hz.js'
async function useMarkdownReport(results, _userConfig) {
let outputLines = []
if (results.length === 0) {
return 'No benchmark results available.'
}
outputLines.push('## ESLint Rule Benchmark Report')
for (let i = 0; i < results.length; i++) {
let testSpecResult = results[i]
outputLines.push('', `### ${testSpecResult.name}`, '')
if (testSpecResult.testCaseResults.length === 0) {
outputLines.push(
'No test cases found or all failed for this specification.',
)
continue
}
let tableRows = []
tableRows.push(
'| Sample | Ops/sec | Avg Time | Median | Min | Max | StdDev |',
'| ------ | ------- | -------- | ------ | --- | --- | ------ |',
)
for (let testCaseResult of testSpecResult.testCaseResults) {
if (testCaseResult.samplesResults.length === 0) {
tableRows.push(`| No samples | N/A | N/A | N/A | N/A | N/A | N/A |`)
continue
}
for (let sampleResult of testCaseResult.samplesResults) {
let sampleName = sampleResult.name.replace(
`${testCaseResult.name} on `,
'',
)
let rowData = [
sampleName,
formatHz(sampleResult.metrics.hz),
formatMs(sampleResult.metrics.mean),
formatMs(sampleResult.metrics.median),
formatMs(sampleResult.metrics.min),
formatMs(sampleResult.metrics.max),
formatDeviation(sampleResult.metrics.stdDev),
]
tableRows.push(`| ${rowData.join(' | ')} |`)
}
}
outputLines.push(...tableRows)
if (i < results.length - 1) {
outputLines.push('')
}
}
let systemInfo = await collectSystemInfo()
outputLines.push('', formatSystemInfoMarkdown(systemInfo))
return outputLines.join('\n')
}
function formatSystemInfoMarkdown(systemInfo) {
let runTime = [
`Node.js ${systemInfo.nodeVersion}`,
`V8 ${systemInfo.v8Version}`,
`ESLint ${systemInfo.eslintVersion}`,
]
let platform = [
`${systemInfo.platform} ${systemInfo.arch} (${systemInfo.osRelease})`,
]
let hardware = [
`${systemInfo.cpuModel} (${systemInfo.cpuCount} cores, ${systemInfo.cpuSpeedMHz} MHz)`,
`${systemInfo.totalMemoryGb} GB RAM`,
]
let formatList = new Intl.ListFormat('en-US', {
type: 'conjunction',
style: 'narrow',
})
return [
'### System Information',
'',
`**Runtime:** ${formatList.format(runTime)}`,
`**Platform:** ${formatList.format(platform)}`,
`**Hardware:** ${formatList.format(hardware)}`,
].join('\n')
}
export { useMarkdownReport }