|
| 1 | +/* eslint-disable strict */ |
| 2 | + |
| 3 | +import util from 'node:util'; |
| 4 | +import fs from 'node:fs'; |
| 5 | +import os from 'node:os'; |
| 6 | +import benchmark from 'benchmark'; |
| 7 | +import { benchmarks } from './benchmarks.mjs'; |
| 8 | + |
| 9 | +const hw = os.cpus(); |
| 10 | +const ram = os.totalmem() / 1024 ** 3; |
| 11 | +const platform = { name: hw[0].model, cores: hw.length, ram: `${ram}GB` }; |
| 12 | + |
| 13 | +const systemInfo = () => |
| 14 | + [ |
| 15 | + `\n- cpu: ${platform.name}`, |
| 16 | + `- cores: ${platform.cores}`, |
| 17 | + `- arch: ${os.arch()}`, |
| 18 | + `- os: ${process.platform} (${os.release()})`, |
| 19 | + `- ram: ${platform.ram}\n` |
| 20 | + ].join('\n'); |
| 21 | +console.log(systemInfo()); |
| 22 | + |
| 23 | +const suite = new benchmark.Suite(); |
| 24 | + |
| 25 | +for (const bench of benchmarks) suite.add(bench.name, bench); |
| 26 | + |
| 27 | +suite |
| 28 | + .on('cycle', function logBenchmark(event) { |
| 29 | + console.log(String(event.target)); |
| 30 | + }) |
| 31 | + .on('complete', function outputPerfSend() { |
| 32 | + const data = Array.from(this).map(bench => ({ |
| 33 | + info: { test_name: bench.name }, |
| 34 | + metrics: [{ name: 'ops_per_sec', value: bench.hz }] |
| 35 | + })); |
| 36 | + console.log(util.inspect(data, { depth: Infinity, colors: true })); |
| 37 | + fs.writeFileSync('customBenchmarkResults.json', JSON.stringify(data), 'utf8'); |
| 38 | + }) |
| 39 | + .run(); |
0 commit comments