This is my example code
const _performance = require('perf_hooks').performance;
someFunction= ()=>{
    _performance.mark('mark A')
    // Do something
    const a= Array(100000)
    var boo =true;
    a.forEach(el=>{
        boo = ! boo
    })
    _performance.mark('mark B')
    _performance.measure('total','mark B','mark A');
    var measurments = _performance.getEntriesByType('measure');
    measurments.forEach(measurment =>{
        console.log(measurment.name + ' ' + measurment.duration)
    } )
}
someFunction();
It crashes with the error message
TypeError: _performance.getEntriesByType is not a function
Any idea why is this happening? I am using node v10.7.0 on windows 10
As of the latest perf_hooks API, the getEntriesByType() function is a method of PerformanceObserverEntryList. Try this instead:
const { performance, PerformanceObserver} = require('perf_hooks')
const obs = new PerformanceObserver((items) => {
    items.getEntries().forEach((item) => {
        console.log(item.name, + ' ' + item.duration)
    })
})
obs.observe({entryTypes: ['measure']})
function someFunction() {
    // Do something
    const a = Array(100000)
    var boo =true;
    a.forEach(el⇒{
        boo = ! boo
    })
}
performance.mark('mark A')
someFunction();
performance.mark('mark B')
performance.measure('total','mark A','mark B');
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With