On this page

    perf_hooks.monitorEventLoopDelay(options?): ELDHistogram
    Attributes
    options:Object
    samplePerIteration?:boolean
    When true, samples are taken once per event loop iteration. Default: false.
    resolution?:number
    The sampling rate in milliseconds for interval-based sampling. Must be greater than zero. This option is ignored when samplePerIteration is true. Default: 10.
    lowest?:number | bigint
    The lowest discernible delay, in nanoseconds. Must be an integer value greater than 0. Default: 1 when samplePerIteration is true, otherwise 1000.
    highest?:number | bigint
    The highest recordable delay, in nanoseconds. Must be an integer value that is equal to or greater than two times lowest. Default: 2n ** 63n - 1n.
    figures?:number
    The number of accuracy digits. Must be an integer between 1 and 5. Default: 3.
    Returns:ELDHistogram

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

    Creates a histogram object that samples and reports the event loop delay over time. The delays will be reported in nanoseconds.

    By default, the histogram is updated by a timer using the configured resolution. When samplePerIteration is true, samples are taken once per event loop iteration using uv_prepare_t and uv_check_t hooks. In that mode, the histogram does not keep the loop alive or force additional iterations when the application is idle. The two sampling modes produce significantly different results and should not be compared directly.

    The lowest, highest, and figures options configure the histogram as they do for perf_hooks.createHistogram(). lowest must be greater than 0 because an event loop delay of zero is not possible: the event loop has a minimal overhead, and the measurement itself depends on the event loop turning. Delays greater than highest are not recorded, and are counted by histogram.exceeds instead. With interval-based sampling, every sample includes the resolution, so highest should be well above resolution * 1e6. The histogram's memory use depends on these options, not on the number of samples.

    import { monitorEventLoopDelay } from 'node:perf_hooks';
    
    const h = monitorEventLoopDelay({ resolution: 20 });
    h.enable();
    // Do something.
    h.disable();
    console.log(h.min);
    console.log(h.max);
    console.log(h.mean);
    console.log(h.stddev);
    console.log(h.percentiles);
    console.log(h.percentile(50));
    console.log(h.percentile(99));
    const { monitorEventLoopDelay } = require('node:perf_hooks');
    const h = monitorEventLoopDelay({ resolution: 20 });
    h.enable();
    // Do something.
    h.disable();
    console.log(h.min);
    console.log(h.max);
    console.log(h.mean);
    console.log(h.stddev);
    console.log(h.percentiles);
    console.log(h.percentile(50));
    console.log(h.percentile(99));