import { performance } from "perf_hooks" ; interface PerformanceTiming { started : number ; name : string ; } class PerformanceTimingsClass { timings : Record < string , PerformanceTiming > = { } ; start ( name , id ? ) { if ( ! id ) { id = "" + Math . random ( ) ; } this . timings [ id ] = { started : performance . now ( ) , name } ; return id ; } end ( id ) { const T = this . timings [ id ] ; if ( T ) { console . log ( `measure [${ T . name }]: ${ performance . now ( ) - T . started }ms` ) ; delete this . timings [ id ] ; } } } export const PerformanceTimings = new PerformanceTimingsClass ( ) ;