From 40655c266f7ff8bd00632a8f336a4cf5c69d8677 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Sat, 26 Oct 2024 20:02:47 +0900 Subject: [PATCH] Refactor PerformanceDebugger class --- src/ts/storage/globalApi.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/ts/storage/globalApi.ts b/src/ts/storage/globalApi.ts index fe89a82f..e18583a9 100644 --- a/src/ts/storage/globalApi.ts +++ b/src/ts/storage/globalApi.ts @@ -2060,14 +2060,14 @@ export async function loadInternalBackup(){ export class PerformanceDebugger{ kv:{[key:string]:number[]} = {} - start:number - end:number + startTime:number + endTime:number /** * Starts the timing measurement. */ - startTiming(){ - this.start = performance.now() + start(){ + this.startTime = performance.now() } /** @@ -2076,11 +2076,11 @@ export class PerformanceDebugger{ * @param {string} key - The key to associate with the recorded time. */ endAndRecord(key:string){ - this.end = performance.now() + this.endTime = performance.now() if(!this.kv[key]){ this.kv[key] = [] } - this.kv[key].push(this.end - this.start) + this.kv[key].push(this.endTime - this.startTime) } /** @@ -2090,7 +2090,7 @@ export class PerformanceDebugger{ */ endAndRecordAndStart(key:string){ this.endAndRecord(key) - this.startTiming() + this.start() } /** @@ -2106,4 +2106,13 @@ export class PerformanceDebugger{ console.table(table) } + + combine(other:PerformanceDebugger){ + for(const key in other.kv){ + if(!this.kv[key]){ + this.kv[key] = [] + } + this.kv[key].push(...other.kv[key]) + } + } } \ No newline at end of file