@@ -550,12 +550,8 @@ namespace ts {
550550 }
551551
552552 function compile ( fileNames : string [ ] , compilerOptions : CompilerOptions , compilerHost : CompilerHost ) {
553- ioReadTime = 0 ;
554- ioWriteTime = 0 ;
555- programTime = 0 ;
556- bindTime = 0 ;
557- checkTime = 0 ;
558- emitTime = 0 ;
553+ const hasDiagnostics = compilerOptions . diagnostics || compilerOptions . extendedDiagnostics ;
554+ if ( hasDiagnostics ) performance . enable ( ) ;
559555
560556 const program = createProgram ( fileNames , compilerOptions , compilerHost ) ;
561557 const exitStatus = compileProgram ( ) ;
@@ -566,7 +562,7 @@ namespace ts {
566562 } ) ;
567563 }
568564
569- if ( compilerOptions . diagnostics ) {
565+ if ( hasDiagnostics ) {
570566 const memoryUsed = sys . getMemoryUsage ? sys . getMemoryUsage ( ) : - 1 ;
571567 reportCountStatistic ( "Files" , program . getSourceFiles ( ) . length ) ;
572568 reportCountStatistic ( "Lines" , countLines ( program ) ) ;
@@ -579,17 +575,28 @@ namespace ts {
579575 reportStatisticalValue ( "Memory used" , Math . round ( memoryUsed / 1000 ) + "K" ) ;
580576 }
581577
582- // Individual component times.
583- // Note: To match the behavior of previous versions of the compiler, the reported parse time includes
584- // I/O read time and processing time for triple-slash references and module imports, and the reported
585- // emit time includes I/O write time. We preserve this behavior so we can accurately compare times.
586- reportTimeStatistic ( "I/O read" , ioReadTime ) ;
587- reportTimeStatistic ( "I/O write" , ioWriteTime ) ;
588- reportTimeStatistic ( "Parse time" , programTime ) ;
589- reportTimeStatistic ( "Bind time" , bindTime ) ;
590- reportTimeStatistic ( "Check time" , checkTime ) ;
591- reportTimeStatistic ( "Emit time" , emitTime ) ;
578+ const programTime = performance . getDuration ( "Program" ) ;
579+ const bindTime = performance . getDuration ( "Bind" ) ;
580+ const checkTime = performance . getDuration ( "Check" ) ;
581+ const emitTime = performance . getDuration ( "Emit" ) ;
582+ if ( compilerOptions . extendedDiagnostics ) {
583+ performance . forEachMeasure ( ( name , duration ) => reportTimeStatistic ( `${ name } time` , duration ) ) ;
584+ }
585+ else {
586+ // Individual component times.
587+ // Note: To match the behavior of previous versions of the compiler, the reported parse time includes
588+ // I/O read time and processing time for triple-slash references and module imports, and the reported
589+ // emit time includes I/O write time. We preserve this behavior so we can accurately compare times.
590+ reportTimeStatistic ( "I/O read" , performance . getDuration ( "I/O Read" ) ) ;
591+ reportTimeStatistic ( "I/O write" , performance . getDuration ( "I/O Write" ) ) ;
592+ reportTimeStatistic ( "Parse time" , programTime ) ;
593+ reportTimeStatistic ( "Bind time" , bindTime ) ;
594+ reportTimeStatistic ( "Check time" , checkTime ) ;
595+ reportTimeStatistic ( "Emit time" , emitTime ) ;
596+ }
592597 reportTimeStatistic ( "Total time" , programTime + bindTime + checkTime + emitTime ) ;
598+
599+ performance . disable ( ) ;
593600 }
594601
595602 return { program, exitStatus } ;
0 commit comments