Stability: 2 - Stable

    This module provides an implementation of a subset of the W3C [Web Performance APIs][] as well as additional APIs for Node.js-specific performance measurements.

    Node.js supports the following [Web Performance APIs][]:

    • [High Resolution Time][]
    • [Performance Timeline][]
    • [User Timing][]
    1. const { PerformanceObserver, performance } = require('perf_hooks');
    2. const obs = new PerformanceObserver((items) => {
    3. console.log(items.getEntries()[0].duration);
    4. performance.clearMarks();
    5. });
    6. obs.observe({ entryTypes: ['measure'] });
    7. performance.measure('Start to Now');
    8. performance.mark('A');
    9. doSomeLongRunningProcess(() => {
    10. performance.measure('A to Now', 'A');
    11. performance.mark('B');
    12. performance.measure('A to B', 'A', 'B');
    13. });