Skip to content

Instantly share code, notes, and snippets.

@maradondt
Last active September 2, 2023 11:03
Show Gist options
  • Save maradondt/63528d5056289831ea183db29634b7b1 to your computer and use it in GitHub Desktop.
Save maradondt/63528d5056289831ea183db29634b7b1 to your computer and use it in GitHub Desktop.
function measureExecutionTime(callback: () => void) {
return function () {
const startTime = performance.now();
callback();
const endTime = performance.now();
const executionTime = endTime - startTime;
console.log(`Execution time for '${callback.name}': ${executionTime} milliseconds`);
};
}
export function useEffectWithMeasure(callback: () => void, deps: any[]) {
const measuredCallback = useMemo(() => measureExecutionTime(callback), deps);
useEffect(() => {
measuredCallback();
}, [measuredCallback]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment