MCPcopy Index your code
hub / github.com/nodejs/node / spinAWhile

Function spinAWhile

test/sequential/test-performance-eventloopdelay.js:62–113  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60 m = m * 2;
61 }
62 function spinAWhile() {
63 sleep(1000);
64 if (--m > 0) {
65 setTimeout(spinAWhile, common.platformTimeout(500));
66 } else {
67 // Give the histogram a chance to record final samples before disabling.
68 // This helps on slower systems where sampling may be delayed.
69 setImmediate(common.mustCall(() => {
70 histogram.disable();
71 // The values are non-deterministic, so we just check that a value is
72 // present, as opposed to a specific value.
73 assert(histogram.count > 0, `Expected samples to be recorded, got count=${histogram.count}`);
74 // Min can legitimately be 0: the underlying HDR histogram has a
75 // lowest discernible value of 1us, so samples whose delta falls in
76 // the [0, 1us) bucket are reported as 0. A negative value would
77 // indicate a bug.
78 assert(histogram.min >= 0);
79 assert(histogram.max > 0);
80 assert(histogram.stddev > 0);
81 assert(histogram.mean > 0);
82 assert(histogram.percentiles.size > 0);
83 for (let n = 1; n < 100; n = n + 0.1) {
84 assert(histogram.percentile(n) >= 0);
85 }
86 histogram.reset();
87 assert.strictEqual(histogram.min, 9223372036854776000);
88 assert.strictEqual(histogram.max, 0);
89 assert(Number.isNaN(histogram.stddev));
90 assert(Number.isNaN(histogram.mean));
91 assert.strictEqual(histogram.percentiles.size, 1);
92
93 ['a', false, {}, []].forEach((i) => {
94 assert.throws(
95 () => histogram.percentile(i),
96 {
97 name: 'TypeError',
98 code: 'ERR_INVALID_ARG_TYPE',
99 }
100 );
101 });
102 [-1, 0, 101, NaN].forEach((i) => {
103 assert.throws(
104 () => histogram.percentile(i),
105 {
106 name: 'RangeError',
107 code: 'ERR_OUT_OF_RANGE',
108 }
109 );
110 });
111 }));
112 }
113 }
114 spinAWhile();
115}
116

Calls 8

percentileMethod · 0.80
forEachMethod · 0.65
sleepFunction · 0.50
setTimeoutFunction · 0.50
setImmediateFunction · 0.50
assertFunction · 0.50
disableMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…