Created
January 25, 2019 06:53
-
-
Save golopot/ae7b87723dfedf04a6b6fcf12f9acece to your computer and use it in GitHub Desktop.
Wrap require with a timer for debugging slow loading modules
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
const Timer = () => { | |
let startTime = new Date() | |
return { | |
end () { | |
return (new Date() - startTime) / 1000 | |
} | |
} | |
} | |
const timedRequire = (require) => (path) => { | |
const timer = Timer() | |
const requiredModule = require(path) | |
console.log(`${timer.end().toFixed(2)} ${path}`) | |
return requiredModule | |
} | |
// eslint-disable-next-line no-global-assign | |
require = timedRequire(require) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment