Last active
September 2, 2023 11:03
-
-
Save maradondt/63528d5056289831ea183db29634b7b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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