Created
October 20, 2023 02:33
-
-
Save aprilandjan/0f5ee7c18450df9313506cb5323b5fb2 to your computer and use it in GitHub Desktop.
print output commonjs require time cost
This file contains 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
// place the code at the beginning of your script file | |
// before any other use of 'require' | |
const Module = require('module').Module; | |
const originalLoad = Module._load; | |
Module._load = function (name, parent) { | |
const uid = `${parent} -> ${name}`; | |
console.time(uid); | |
const exports = originalLoad.apply(Module, arguments); | |
console.timeEnd(uid); | |
return exports; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment