File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ onmessage = async (e) => {
2323function loop ( ) {
2424 Electra . init ( input ) ;
2525 Electra . set_source_code ( code ) ;
26+ const start = performance . now ( ) ;
2627 Electra . generate ( ) ;
2728 Electra . step ( ) ;
2829
@@ -35,5 +36,17 @@ function loop() {
3536 postMessage ( { type : "output" , data : output } ) ;
3637 }
3738 }
38- postMessage ( { type : "final" , data : "\n[Program finished]\n" } ) ;
39+ const end = performance . now ( ) ;
40+ const delta_time = ( end - start ) ;
41+ const ms = Math . floor ( delta_time % 1000 ) ;
42+ const seconds = Math . floor ( delta_time / 1e3 ) % 60 ;
43+ const mins = Math . floor ( delta_time / ( 1e3 * 60 ) ) % 60 ;
44+ const hours = Math . floor ( delta_time / ( 1e3 * 3600 ) ) ;
45+ let final_text = "" ;
46+ if ( hours > 0 ) { final_text += `${ hours } h ` ; }
47+ if ( mins > 0 ) { final_text += `${ mins } m ` ; }
48+ if ( seconds > 0 ) { final_text += `${ seconds } s ` ; }
49+ final_text += `${ ms } ms` ;
50+
51+ postMessage ( { type : "final" , data : `\n[Execution completed in ${ final_text } ]\n` } ) ;
3952}
You can’t perform that action at this time.
0 commit comments