diff options
author | Ansh Nanda <anshnanda10@gmail.com> | 2023-05-23 15:28:46 -0700 |
---|---|---|
committer | Ansh Nanda <anshnanda10@gmail.com> | 2023-05-23 15:28:46 -0700 |
commit | fc9e28ca72ce498df8d0902c8e51d226affefd83 (patch) | |
tree | 4f9d54dd7e2cc59852d81d6bf29ea53bec830eca /src/state/models/log.ts | |
parent | b561a51ed9f798194c3c6a72eefab562a773f2c9 (diff) | |
download | voidsky-fc9e28ca72ce498df8d0902c8e51d226affefd83.tar.zst |
slight performance improvements
Diffstat (limited to 'src/state/models/log.ts')
-rw-r--r-- | src/state/models/log.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/state/models/log.ts b/src/state/models/log.ts index d80617139..7c9c37c0d 100644 --- a/src/state/models/log.ts +++ b/src/state/models/log.ts @@ -27,6 +27,7 @@ function genId(): string { export class LogModel { entries: LogEntry[] = [] + timers = new Map<string, number>() constructor() { makeAutoObservable(this) @@ -74,6 +75,21 @@ export class LogModel { ts: Date.now(), }) } + + time = (label = 'default') => { + this.timers.set(label, performance.now()) + } + + timeEnd = (label = 'default', warn = false) => { + const endTime = performance.now() + if (this.timers.has(label)) { + const elapsedTime = endTime - this.timers.get(label)! + console.log(`${label}: ${elapsedTime.toFixed(3)}ms`) + this.timers.delete(label) + } else { + warn && console.warn(`Timer with label '${label}' does not exist.`) + } + } } function detailsToStr(details?: any) { |