Skip to content

Instantly share code, notes, and snippets.

@n3dst4
Created August 13, 2014 08:15
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 n3dst4/317171514441b834d1ea to your computer and use it in GitHub Desktop.
Save n3dst4/317171514441b834d1ea to your computer and use it in GitHub Desktop.
Time how long all your require()s take
/*
* requireTime.js
*
* require()s every thing in your node_modules and tells you how long each one
* took.
*
* USAGE:
* $ cd your_project_folder
* $ node loadTest.js
*
* Based on this comment:
* https://github.com/gulpjs/gulp/issues/282#issuecomment-35482108
*/
var modules = require('fs').readdirSync('node_modules').filter(
function (name) { return name !== '.bin';}
);
console.time("+++TOTAL");
modules.forEach(function (m) {
console.time(m);
try {
require(m);
console.timeEnd(m);
}
catch (e) {
console.warn(m + ": " + e);
}
});
console.timeEnd("+++TOTAL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment