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