On this page

    M

    perf_hooks.importHistogram

    History
    perf_hooks.importHistogram(data): RecordableHistogram
    Attributes
    A CBOR-encoded histogram previously produced by histogram.export().

    Reconstructs a histogram from a CBOR-encoded Uint8Array. The returned histogram is a full RecordableHistogram with all bucket data, configuration, and EWMA state restored. New values can be recorded into it.

    const { createHistogram, importHistogram } = require('node:perf_hooks');
    
    const h = createHistogram();
    for (let i = 1; i <= 1000; i++) h.record(i);
    
    // Serialize and reconstruct
    const data = h.export();
    const h2 = importHistogram(data);
    
    console.log(h2.count);          // 1000
    console.log(h2.percentile(99)); // Same as h.percentile(99)