diff --git a/benches/db_1KiB.ts b/benches/db_1KiB.ts index f2522c6..b950145 100644 --- a/benches/db_1KiB.ts +++ b/benches/db_1KiB.ts @@ -46,8 +46,12 @@ async function main() { }); return summary; } -if (process.argv[1] === url.fileURLToPath(import.meta.url)) { - void main(); + +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/db_1MiB.ts b/benches/db_1MiB.ts index 9eabc38..424aff4 100644 --- a/benches/db_1MiB.ts +++ b/benches/db_1MiB.ts @@ -47,8 +47,11 @@ async function main() { return summary; } -if (process.argv[1] === url.fileURLToPath(import.meta.url)) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/index.ts b/benches/index.ts index fce10d3..b5e9d7e 100644 --- a/benches/index.ts +++ b/benches/index.ts @@ -1,30 +1,31 @@ #!/usr/bin/env ts-node -import fs from 'fs'; -import path from 'path'; +import fs from 'node:fs'; +import path from 'node:path'; import url from 'node:url'; import si from 'systeminformation'; +import { benchesPath } from './utils/utils.js'; import DB1KiB from './db_1KiB.js'; import DB1MiB from './db_1MiB.js'; -const dirname = url.fileURLToPath(new URL('.', import.meta.url)); - async function main(): Promise { - await fs.promises.mkdir(path.join(dirname, 'results'), { recursive: true }); + await fs.promises.mkdir(path.join(benchesPath, 'results'), { + recursive: true, + }); await DB1KiB(); await DB1MiB(); const resultFilenames = await fs.promises.readdir( - path.join(dirname, 'results'), + path.join(benchesPath, 'results'), ); const metricsFile = await fs.promises.open( - path.join(dirname, 'results', 'metrics.txt'), + path.join(benchesPath, 'results', 'metrics.txt'), 'w', ); let concatenating = false; for (const resultFilename of resultFilenames) { if (/.+_metrics\.txt$/.test(resultFilename)) { const metricsData = await fs.promises.readFile( - path.join(dirname, 'results', resultFilename), + path.join(benchesPath, 'results', resultFilename), ); if (concatenating) { await metricsFile.write('\n'); @@ -40,9 +41,16 @@ async function main(): Promise { system: 'model, manufacturer', }); await fs.promises.writeFile( - path.join(dirname, 'results', 'system.json'), + path.join(benchesPath, 'results', 'system.json'), JSON.stringify(systemData, null, 2), ); } -void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } +} + +export default main; diff --git a/benches/results/db_1KiB.chart.html b/benches/results/db_1KiB.chart.html index 25b68a2..32250e6 100644 --- a/benches/results/db_1KiB.chart.html +++ b/benches/results/db_1KiB.chart.html @@ -28,7 +28,7 @@
- +