summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/benchmarks/common/resultsCombinator.js
blob: 253211bb15b00e9e2ca860837284ab01acf9a98f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'

const fs = require('node:fs')
const path = require('node:path')
const getopts = require('getopts')
const systemInformation = require('systeminformation')
const { loadResults } = require('photofinish')

const options = getopts(process.argv.slice(1), {
  alias: {
    resultsDir: 'r',
    precision: 'p'
  },
  default: {}
})

const { generateTable } = require('photofinish')

async function getSpecs () {
  const cpuInfo = await systemInformation.cpu()

  return {
    cpu: {
      brand: cpuInfo.brand,
      speed: `${cpuInfo.speed} GHz`
    }
  }
}

async function saveTable () {
  const baseResultsDir = options.resultsDir
  const benchmarkResults = await loadResults(baseResultsDir)

  const table = generateTable(benchmarkResults, {
    precision: options.precision,
    sortBy: [
      { field: 'meanTimeNs', order: 'asc' }
    ]
  })

  const specs = await getSpecs()

  console.log(specs)
  console.log(table)

  const targetFilePath = path.resolve(baseResultsDir, 'results.md')
  fs.writeFileSync(
    targetFilePath,
    `${table}` +
      `\n\n**Specs**: ${specs.cpu.brand} (${specs.cpu.speed})`
  )
}

saveTable()