Created
April 16, 2019 01:03
-
-
Save deleteman/bf162e9b2f006c123653f214ce90626c to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const { | |
performance, | |
PerformanceObserver | |
} = require('perf_hooks'); | |
const mod = require('module'); | |
// Monkey patch the require function | |
mod.Module.prototype.require = performance.timerify(mod.Module.prototype.require); | |
require = performance.timerify(require); | |
// Activate the observer | |
const obs = new PerformanceObserver((list) => { | |
const entries = list.getEntries(); | |
entries.forEach((entry) => { | |
console.log(`require('${entry[0]}')`, entry.duration); | |
}); | |
obs.disconnect(); | |
}); | |
obs.observe({ entryTypes: ['function'], buffered: true }); | |
require(‘getpass’); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment