|
1 | | -#!/usr/bin/env ts-node |
| 1 | +#!/usr/bin/env tsx |
2 | 2 |
|
3 | | -import type { Summary } from 'benny/lib/internal/common-types.js'; |
4 | | -import fs from 'fs'; |
5 | | -import path from 'path'; |
| 3 | +import fs from 'node:fs'; |
| 4 | +import path from 'node:path'; |
6 | 5 | import url from 'node:url'; |
7 | 6 | import si from 'systeminformation'; |
8 | | -import { fsWalk, resultsPath, suitesPath } from './utils.js'; |
9 | | - |
10 | | -const dirname = url.fileURLToPath(new URL('.', import.meta.url)); |
11 | | -console.log('dirname', dirname); |
| 7 | +import { benchesPath } from './utils/utils.js'; |
| 8 | +import buffer_allocation from './buffer_allocation.js'; |
| 9 | +import stream_1KiB from './stream_1KiB.js'; |
| 10 | +import stream_1KiB_FFI from './stream_1KiB_FFI.js'; |
12 | 11 |
|
13 | 12 | async function main(): Promise<void> { |
14 | | - console.log('mkdir', path.join(dirname, 'results')); |
15 | | - await fs.promises.mkdir(url.pathToFileURL(path.join(dirname, 'results')), { |
| 13 | + await fs.promises.mkdir(path.join(benchesPath, 'results'), { |
16 | 14 | recursive: true, |
17 | 15 | }); |
18 | | - // Running all suites |
19 | | - for await (const suitePath of fsWalk(suitesPath)) { |
20 | | - // Skip over non-ts and non-js files |
21 | | - const ext = path.extname(suitePath); |
22 | | - if (ext !== '.ts' && ext !== '.js') { |
23 | | - continue; |
24 | | - } |
25 | | - const suite: () => Promise<Summary> = (await import(suitePath)).default; |
26 | | - // Skip default exports that are not functions and are not called "main" |
27 | | - // They might be utility files |
28 | | - if (typeof suite === 'function' && suite.name === 'main') { |
29 | | - await suite(); |
30 | | - } |
31 | | - } |
32 | | - // Concatenating metrics |
33 | | - const metricsPath = path.join(resultsPath, 'metrics.txt'); |
34 | | - await fs.promises.rm(url.pathToFileURL(metricsPath), { force: true }); |
| 16 | + await buffer_allocation(); |
| 17 | + await stream_1KiB(); |
| 18 | + await stream_1KiB_FFI(); |
| 19 | + const resultFilenames = await fs.promises.readdir( |
| 20 | + path.join(benchesPath, 'results'), |
| 21 | + ); |
| 22 | + const metricsFile = await fs.promises.open( |
| 23 | + path.join(benchesPath, 'results', 'metrics.txt'), |
| 24 | + 'w', |
| 25 | + ); |
35 | 26 | let concatenating = false; |
36 | | - for await (const metricPath of fsWalk(resultsPath)) { |
37 | | - // Skip over non-metrics files |
38 | | - if (!metricPath.endsWith('_metrics.txt')) { |
39 | | - continue; |
| 27 | + for (const resultFilename of resultFilenames) { |
| 28 | + if (/.+_metrics\.txt$/.test(resultFilename)) { |
| 29 | + const metricsData = await fs.promises.readFile( |
| 30 | + path.join(benchesPath, 'results', resultFilename), |
| 31 | + ); |
| 32 | + if (concatenating) { |
| 33 | + await metricsFile.write('\n'); |
| 34 | + } |
| 35 | + await metricsFile.write(metricsData); |
| 36 | + concatenating = true; |
40 | 37 | } |
41 | | - const metricData = await fs.promises.readFile( |
42 | | - url.pathToFileURL(metricPath), |
43 | | - ); |
44 | | - if (concatenating) { |
45 | | - await fs.promises.appendFile(url.pathToFileURL(metricsPath), '\n'); |
46 | | - } |
47 | | - await fs.promises.appendFile(url.pathToFileURL(metricsPath), metricData); |
48 | | - concatenating = true; |
49 | 38 | } |
| 39 | + await metricsFile.close(); |
50 | 40 | const systemData = await si.get({ |
51 | 41 | cpu: '*', |
52 | 42 | osInfo: 'platform, distro, release, kernel, arch', |
53 | 43 | system: 'model, manufacturer', |
54 | 44 | }); |
55 | | - console.log('write file', path.join(dirname, 'results', 'system.json')); |
56 | 45 | await fs.promises.writeFile( |
57 | | - url.pathToFileURL(path.join(dirname, 'results', 'system.json')), |
| 46 | + path.join(benchesPath, 'results', 'system.json'), |
58 | 47 | JSON.stringify(systemData, null, 2), |
59 | 48 | ); |
60 | 49 | } |
61 | 50 |
|
62 | | -if (process.argv[1] === url.fileURLToPath(import.meta.url)) { |
63 | | - void main(); |
| 51 | +if (import.meta.url.startsWith('file:')) { |
| 52 | + const modulePath = url.fileURLToPath(import.meta.url); |
| 53 | + if (process.argv[1] === modulePath) { |
| 54 | + void main(); |
| 55 | + } |
64 | 56 | } |
65 | 57 |
|
66 | 58 | export default main; |
0 commit comments