Skip to content

Commit

Permalink
Merge pull request #137 from melfore/130-timeline-skip-performances-c…
Browse files Browse the repository at this point in the history
…heck-when-not-in-debug-mode

[KonvaTimeLine] PerformanceCheck function refactor
  • Loading branch information
CrisGrud committed Oct 26, 2023
2 parents b6f2c44 + ba3ddc2 commit 8bce758
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { DateTime } from "luxon";
import { logDebug } from "./logger";

export const executeWithPerfomanceCheck = <T>(tag: string, item: string, fn: () => T): T => {
logDebug(tag, `Running ${item}`);
const start = DateTime.now().toMillis();
if (window.__MELFORE_KONVA_TIMELINE_DEBUG__) {
logDebug(tag, `Running ${item}`);
const start = DateTime.now().toMillis();
const fnResult = fn();
const end = DateTime.now().toMillis();
logDebug(tag, `${item} calculation took ${end - start} ms`);
return fnResult;
}
const result = fn();
const end = DateTime.now().toMillis();

logDebug(tag, `${item} calculation took ${end - start} ms`);
return result;
};

0 comments on commit 8bce758

Please sign in to comment.