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BAAiB,CAAC,UAAU,GAAG,GAAG,CAAC;IACrC,CAAC;IAEa,kCAAgB,GAA9B;QACE,iBAAiB,CAAC,UAAU,GAAG,UAAU,CAAC,cAAM,OAAA,iBAAiB,CAAC,KAAK,EAAE,EAAzB,CAAyB,EAAE,cAAc,CAAC,CAAC;IAC7F,CAAC;IAvCa,yBAAO,GAAiB,EAAE,CAAC;IAwC3C,wBAAC;CAAA,AAzCD,IAyCC;SAzCY,iBAAiB","sourcesContent":["declare const setTimeout: (cb: () => void, delay: number) => number;\n\n/**\n * PerfData interface.\n *\n * @internal\n */\nexport interface IPerfData {\n  duration: number;\n  timeStamp: number;\n}\n\n/**\n * PerfMeasurement interface.\n *\n * @internal\n */\nexport interface IPerfMeasurement {\n  totalDuration: number;\n  count: number;\n  all: IPerfData[];\n}\n\n/**\n * PerfSummary interface.\n *\n * @internal\n */\nexport interface IPerfSummary {\n  [key: string]: IPerfMeasurement;\n}\n\nconst now: () => number = () =>\n  typeof performance !== 'undefined' && !!performance.now ? performance.now() : Date.now();\n\nconst RESET_INTERVAL = 3 * 60 * 1000; // auto reset every 3 minutes\n\n/**\n * Performance helper class for measuring things.\n *\n * @public\n * {@docCategory FabricPerformance}\n */\nexport class FabricPerformance {\n  public static summary: IPerfSummary = {};\n  private static _timeoutId: number;\n\n  /**\n   * Measures execution time of the given syncronous function. If the same logic is executed multiple times,\n   * each individual measurement will be collected as well the overall numbers.\n   * @param name - The name of this measurement\n   * @param func - The logic to be measured for execution time\n   */\n  public static measure(name: string, func: () => void): void {\n    if (FabricPerformance._timeoutId) {\n      FabricPerformance.setPeriodicReset();\n    }\n    const start = now();\n    func();\n    const end = now();\n    const measurement: IPerfMeasurement = FabricPerformance.summary[name] || {\n      totalDuration: 0,\n      count: 0,\n      all: [],\n    };\n    const duration = end - start;\n    measurement.totalDuration += duration;\n    measurement.count++;\n    measurement.all.push({\n      duration: duration,\n      timeStamp: end,\n    });\n    FabricPerformance.summary[name] = measurement;\n  }\n\n  public static reset(): void {\n    FabricPerformance.summary = {};\n    clearTimeout(FabricPerformance._timeoutId);\n    FabricPerformance._timeoutId = NaN;\n  }\n\n  public static setPeriodicReset(): void {\n    FabricPerformance._timeoutId = setTimeout(() => FabricPerformance.reset(), RESET_INTERVAL);\n  }\n}\n"]}