From bf33fe541cea12c99975aafe2f21a6d19e47f914 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Fri, 28 Mar 2025 09:55:02 +1100 Subject: [PATCH 1/5] build: adding `NPM_TOKEN` secret --- benches/db_1KiB.ts | 8 ++++++-- benches/db_1MiB.ts | 7 +++++-- benches/index.ts | 28 ++++++++++++++++++---------- benches/utils/utils.ts | 20 +++++++++++--------- 4 files changed, 40 insertions(+), 23 deletions(-) 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/utils/utils.ts b/benches/utils/utils.ts index 7c9f4d2..ce8ec15 100644 --- a/benches/utils/utils.ts +++ b/benches/utils/utils.ts @@ -1,31 +1,33 @@ -import fs from 'fs'; -import path from 'path'; +import fs from 'node:fs'; +import path from 'node:path'; import url from 'node:url'; import b from 'benny'; import { codeBlock } from 'common-tags'; -import packageJson from '../../package.json'; +import packageJson from '../../package.json' assert { type: 'json' }; -const dirname = url.fileURLToPath(new URL('.', import.meta.url)); +const benchesPath = path.dirname( + path.dirname(url.fileURLToPath(import.meta.url)), +); const suiteCommon = [ b.cycle(), b.complete(), b.save({ file: (summary) => summary.name, - folder: path.join(dirname, '../results'), + folder: path.join(benchesPath, 'results'), version: packageJson.version, details: true, }), b.save({ file: (summary) => summary.name, - folder: path.join(dirname, '../results'), + folder: path.join(benchesPath, 'results'), version: packageJson.version, format: 'chart.html', }), b.complete((summary) => { const filePath = path.join( - dirname, - '../results', + benchesPath, + 'results', summary.name + '_metrics.txt', ); fs.writeFileSync( @@ -61,4 +63,4 @@ const suiteCommon = [ }), ]; -export { suiteCommon }; +export { benchesPath, suiteCommon }; From 541bdb8920323f764bba2f68e7e7cc39f316951d Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Fri, 28 Mar 2025 10:01:44 +1100 Subject: [PATCH 2/5] bench: running benchmarks --- benches/results/db_1KiB.chart.html | 14 +- benches/results/db_1KiB.json | 572 +++++++++++++-------------- benches/results/db_1KiB_metrics.txt | 22 +- benches/results/db_1MiB.chart.html | 14 +- benches/results/db_1MiB.json | 592 ++++++++++++++-------------- benches/results/db_1MiB_metrics.txt | 24 +- benches/results/metrics.txt | 46 +-- benches/results/system.json | 2 +- 8 files changed, 633 insertions(+), 653 deletions(-) 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 @@
- +