perf_hooks: implement SlidingWindowHistogram by jasnell · Pull Request #65825 · nodejs/node · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions benchmark/perf_hooks/histogram-qrde.js
24 changes: 24 additions & 0 deletions benchmark/perf_hooks/histogram-sliding-window-record.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const assert = require('assert');
const common = require('../common.js');
const { createSlidingWindowHistogram } = require('perf_hooks');

const bench = common.createBenchmark(main, {
n: [1e6],
mode: ['count', 'time'],
chunks: [6],
});

function main({ n, mode, chunks }) {
const options = mode === 'count' ?
{ chunks, recordsPerChunk: 1000 } :
{ chunks, chunkDuration: 1 };
const histogram = createSlidingWindowHistogram(options);

bench.start();
for (let i = 0; i < n; i++) histogram.record((i % 1000) + 1);
bench.end(n);

assert.ok(histogram.snapshot().count > 0);
}
29 changes: 29 additions & 0 deletions benchmark/perf_hooks/histogram-sliding-window-snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const assert = require('assert');
const common = require('../common.js');
const { createSlidingWindowHistogram } = require('perf_hooks');

const bench = common.createBenchmark(main, {
n: [100],
chunks: [2, 8],
recordsPerChunk: [1000],
});

let snapshot;

function main({ n, chunks, recordsPerChunk }) {
const histogram = createSlidingWindowHistogram({
chunks,
recordsPerChunk,
});
for (let i = 0; i < chunks * recordsPerChunk; i++) {
histogram.record((i % 1000) + 1);
}

bench.start();
for (let i = 0; i < n; i++) snapshot = histogram.snapshot();
bench.end(n);

assert.strictEqual(snapshot.count, chunks * recordsPerChunk);
}
180 changes: 180 additions & 0 deletions doc/api/perf_hooks.md
Loading