Skip to content

Instantly share code, notes, and snippets.

@golopot
Created January 25, 2019 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save golopot/ae7b87723dfedf04a6b6fcf12f9acece to your computer and use it in GitHub Desktop.
Save golopot/ae7b87723dfedf04a6b6fcf12f9acece to your computer and use it in GitHub Desktop.
Wrap require with a timer for debugging slow loading modules
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