• fn {Function}

    This property is an extension by Node.js. It is not available in Web browsers.

    Wraps a function within a new function that measures the running time of the wrapped function. A PerformanceObserver must be subscribed to the 'function' event type in order for the timing details to be accessed.

    1. const {
    2. performance,
    3. PerformanceObserver
    4. } = require('perf_hooks');
    5. function someFunction() {
    6. console.log('hello world');
    7. }
    8. const wrapped = performance.timerify(someFunction);
    9. const obs = new PerformanceObserver((list) => {
    10. console.log(list.getEntries()[0].duration);
    11. obs.disconnect();
    12. });
    13. obs.observe({ entryTypes: ['function'] });
    14. // A performance timeline entry will be created
    15. wrapped();