11#!/usr/bin/env ts-node
22
3- import fs from 'fs' ;
4- import path from 'path' ;
3+ import fs from 'node: fs' ;
4+ import path from 'node: path' ;
55import url from 'node:url' ;
66import si from 'systeminformation' ;
7+ import { benchesPath } from './utils/utils.js' ;
78import DB1KiB from './db_1KiB.js' ;
89import DB1MiB from './db_1MiB.js' ;
910
10- const dirname = url . fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
11-
1211async function main ( ) : Promise < void > {
13- await fs . promises . mkdir ( path . join ( dirname , 'results' ) , { recursive : true } ) ;
12+ await fs . promises . mkdir ( path . join ( benchesPath , 'results' ) , {
13+ recursive : true ,
14+ } ) ;
1415 await DB1KiB ( ) ;
1516 await DB1MiB ( ) ;
1617 const resultFilenames = await fs . promises . readdir (
17- path . join ( dirname , 'results' ) ,
18+ path . join ( benchesPath , 'results' ) ,
1819 ) ;
1920 const metricsFile = await fs . promises . open (
20- path . join ( dirname , 'results' , 'metrics.txt' ) ,
21+ path . join ( benchesPath , 'results' , 'metrics.txt' ) ,
2122 'w' ,
2223 ) ;
2324 let concatenating = false ;
2425 for ( const resultFilename of resultFilenames ) {
2526 if ( / .+ _ m e t r i c s \. t x t $ / . test ( resultFilename ) ) {
2627 const metricsData = await fs . promises . readFile (
27- path . join ( dirname , 'results' , resultFilename ) ,
28+ path . join ( benchesPath , 'results' , resultFilename ) ,
2829 ) ;
2930 if ( concatenating ) {
3031 await metricsFile . write ( '\n' ) ;
@@ -40,9 +41,16 @@ async function main(): Promise<void> {
4041 system : 'model, manufacturer' ,
4142 } ) ;
4243 await fs . promises . writeFile (
43- path . join ( dirname , 'results' , 'system.json' ) ,
44+ path . join ( benchesPath , 'results' , 'system.json' ) ,
4445 JSON . stringify ( systemData , null , 2 ) ,
4546 ) ;
4647}
4748
48- void main ( ) ;
49+ if ( import . meta. url . startsWith ( 'file:' ) ) {
50+ const modulePath = url . fileURLToPath ( import . meta. url ) ;
51+ if ( process . argv [ 1 ] === modulePath ) {
52+ void main ( ) ;
53+ }
54+ }
55+
56+ export default main ;
0 commit comments