11using System . Diagnostics ;
22using System . Numerics ;
3+ using System . Runtime . InteropServices ;
34using System . Runtime . Intrinsics ;
45using System . Runtime . Intrinsics . X86 ;
56using System . Text ;
@@ -10,14 +11,44 @@ internal class Program
1011{
1112 private static void Main ( string [ ] args )
1213 {
13- var sw = Stopwatch . StartNew ( ) ;
14+ var path = args . Length > 0 ? args [ 0 ] : "D:/tmp/measurements_1B.txt" ;
15+
1416 Console . OutputEncoding = Encoding . UTF8 ;
15- var path = args . Length > 0 ? args [ 0 ] : "D:/tmp/measurements_1B_10K.txt" ;
17+
18+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) || args . Contains ( "--worker" ) )
19+ DoWork ( path ) ;
20+ else
21+ StartSubprocess ( path ) ;
22+ }
23+
24+ private static void DoWork ( string path )
25+ {
1626 using ( var app = new App ( path ) )
1727 {
28+ var sw = Stopwatch . StartNew ( ) ;
1829 app . PrintResult ( ) ;
30+ sw . Stop ( ) ;
31+ Console . Out . Close ( ) ;
1932 }
20- sw . Stop ( ) ;
21- Console . WriteLine ( $ "Finished in: { sw . ElapsedMilliseconds : N0} ms") ;
33+ }
34+
35+ private static void StartSubprocess ( string path )
36+ {
37+ string parentProcessPath = Process . GetCurrentProcess ( ) . MainModule ! . FileName ;
38+
39+ Console . WriteLine ( $ "CMD: -c \" { parentProcessPath } { path } --worker & \" ") ;
40+
41+ var processStartInfo = new ProcessStartInfo
42+ {
43+ FileName = "sh" , // parentProcessPath,
44+ Arguments = $ "-c \" { parentProcessPath } { path } --worker & \" ",
45+ RedirectStandardOutput = true ,
46+ UseShellExecute = false ,
47+ CreateNoWindow = false ,
48+ } ;
49+
50+ var process = Process . Start ( processStartInfo ) ;
51+ string ? output = process ! . StandardOutput . ReadLine ( ) ;
52+ Console . Write ( output ) ;
2253 }
2354}
0 commit comments