Skip to content

Instantly share code, notes, and snippets.

@aprilandjan
Created October 20, 2023 02:33
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 aprilandjan/0f5ee7c18450df9313506cb5323b5fb2 to your computer and use it in GitHub Desktop.
Save aprilandjan/0f5ee7c18450df9313506cb5323b5fb2 to your computer and use it in GitHub Desktop.
print output commonjs require time cost
// 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