Debian Codegraph @

fastify-busboy/benchmarks/common/resultsCombinator.js

raw
1 'use strict'
2
3 const fs = require('node:fs')
4 const path = require('node:path')
5 const getopts = require('getopts')
6 const systemInformation = require('systeminformation')
7 const { loadResults } = require('photofinish')
8
9 const options = getopts(process.argv.slice(1), {
10 alias: {
11 resultsDir: 'r',
12 precision: 'p'
13 },
14 default: {}
15 })
16
17 const { generateTable } = require('photofinish')
18
19 async function getSpecs () {
20 const cpuInfo = await systemInformation.cpu()
21
22 return {
23 cpu: {
24 brand: cpuInfo.brand,
25 speed: `${cpuInfo.speed} GHz`
26 }
27 }
28 }
29
30 async function saveTable () {
31 const baseResultsDir = options.resultsDir
32 const benchmarkResults = await loadResults(baseResultsDir)
33
34 const table = generateTable(benchmarkResults, {
35 precision: options.precision,
36 sortBy: [
37 { field: 'meanTimeNs', order: 'asc' }
38 ]
39 })
40
41 const specs = await getSpecs()
42
43 console.log(specs)
44 console.log(table)
45
46 const targetFilePath = path.resolve(baseResultsDir, 'results.md')
47 fs.writeFileSync(
48 targetFilePath,
49 `${table}` +
50 `\n\n**Specs**: ${specs.cpu.brand} (${specs.cpu.speed})`
51 )
52 }
53
54 saveTable()