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
+ import url from 'node:url' ;
5
6
import si from 'systeminformation' ;
6
- import workerManager from './worker_manager' ;
7
+ import workerManager from './worker_manager.js ' ;
7
8
8
9
async function main ( ) : Promise < void > {
9
- await fs . promises . mkdir ( path . join ( __dirname , 'results' ) , { recursive : true } ) ;
10
+ await fs . promises . mkdir ( path . join ( benchesPath , 'results' ) , {
11
+ recursive : true ,
12
+ } ) ;
10
13
await workerManager ( ) ;
11
14
const resultFilenames = await fs . promises . readdir (
12
- path . join ( __dirname , 'results' ) ,
15
+ path . join ( benchesPath , 'results' ) ,
13
16
) ;
14
17
const metricsFile = await fs . promises . open (
15
- path . join ( __dirname , 'results' , 'metrics.txt' ) ,
18
+ path . join ( benchesPath , 'results' , 'metrics.txt' ) ,
16
19
'w' ,
17
20
) ;
18
21
let concatenating = false ;
19
22
for ( const resultFilename of resultFilenames ) {
20
23
if ( / .+ _ m e t r i c s \. t x t $ / . test ( resultFilename ) ) {
21
24
const metricsData = await fs . promises . readFile (
22
- path . join ( __dirname , 'results' , resultFilename ) ,
25
+ path . join ( benchesPath , 'results' , resultFilename ) ,
23
26
) ;
24
27
if ( concatenating ) {
25
28
await metricsFile . write ( '\n' ) ;
@@ -35,9 +38,16 @@ async function main(): Promise<void> {
35
38
system : 'model, manufacturer' ,
36
39
} ) ;
37
40
await fs . promises . writeFile (
38
- path . join ( __dirname , 'results' , 'system.json' ) ,
41
+ path . join ( benchesPath , 'results' , 'system.json' ) ,
39
42
JSON . stringify ( systemData , null , 2 ) ,
40
43
) ;
41
44
}
42
45
43
- void main ( ) ;
46
+ if ( import . meta. url . startsWith ( 'file:' ) ) {
47
+ const modulePath = url . fileURLToPath ( import . meta. url ) ;
48
+ if ( process . argv [ 1 ] === modulePath ) {
49
+ void main ( ) ;
50
+ }
51
+ }
52
+
53
+ export default main ;
0 commit comments