Created
November 29, 2022 02:03
-
-
Save KoryNunn/4fdd6df47a72e0f53844014b0c8298bf to your computer and use it in GitHub Desktop.
function performance timing wrapper
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 time(fn) { | |
return async (...args) => { | |
const stack = new Error().stack.split('\n').slice(1, 5).join('\n'); | |
const start = performance.now(); | |
const result = await fn(...args); | |
const end = performance.now(); | |
performance.measure(`${fn.name}:\n${stack}`, { start, end }); | |
return result; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment