Skip to content
Closed
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
10 changes: 8 additions & 2 deletions test/sequential/test-performance-eventloopdelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const assert = require('assert');
const {
monitorEventLoopDelay
} = require('perf_hooks');
const { sleep } = require('internal/util');

{
const histogram = monitorEventLoopDelay();
Expand Down Expand Up @@ -50,12 +49,19 @@ const { sleep } = require('internal/util');
});
}

// Can't use `sleep` from internal/util because it doesn't do a busy wait
// which means we can get 0 values in the histogram sometimes.
function busySleep(ms) {
const target = Date.now() + ms;
while (Date.now() < target) {}
}

{
const histogram = monitorEventLoopDelay({ resolution: 1 });
histogram.enable();
let m = 5;
function spinAWhile() {
sleep(1000);
busySleep(1000);
if (--m > 0) {
setTimeout(spinAWhile, common.platformTimeout(500));
} else {
Expand Down