1
1
#!/usr/bin/env ts-node
2
2
3
- import fs from 'fs' ;
4
- import path from 'path' ;
3
+ import fs from 'node: fs' ;
4
+ import path from 'node: path' ;
5
5
import url from 'node:url' ;
6
6
import si from 'systeminformation' ;
7
+ import { benchesPath } from './utils/utils.js' ;
7
8
import DB1KiB from './db_1KiB.js' ;
8
9
import DB1MiB from './db_1MiB.js' ;
9
10
10
- const dirname = url . fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
11
-
12
11
async 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
+ } ) ;
14
15
await DB1KiB ( ) ;
15
16
await DB1MiB ( ) ;
16
17
const resultFilenames = await fs . promises . readdir (
17
- path . join ( dirname , 'results' ) ,
18
+ path . join ( benchesPath , 'results' ) ,
18
19
) ;
19
20
const metricsFile = await fs . promises . open (
20
- path . join ( dirname , 'results' , 'metrics.txt' ) ,
21
+ path . join ( benchesPath , 'results' , 'metrics.txt' ) ,
21
22
'w' ,
22
23
) ;
23
24
let concatenating = false ;
24
25
for ( const resultFilename of resultFilenames ) {
25
26
if ( / .+ _ m e t r i c s \. t x t $ / . test ( resultFilename ) ) {
26
27
const metricsData = await fs . promises . readFile (
27
- path . join ( dirname , 'results' , resultFilename ) ,
28
+ path . join ( benchesPath , 'results' , resultFilename ) ,
28
29
) ;
29
30
if ( concatenating ) {
30
31
await metricsFile . write ( '\n' ) ;
@@ -40,9 +41,16 @@ async function main(): Promise<void> {
40
41
system : 'model, manufacturer' ,
41
42
} ) ;
42
43
await fs . promises . writeFile (
43
- path . join ( dirname , 'results' , 'system.json' ) ,
44
+ path . join ( benchesPath , 'results' , 'system.json' ) ,
44
45
JSON . stringify ( systemData , null , 2 ) ,
45
46
) ;
46
47
}
47
48
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