-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtime-mode.js
More file actions
33 lines (25 loc) · 1012 Bytes
/
Copy pathtime-mode.js
File metadata and controls
33 lines (25 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { Suite } = require('../lib');
const timeSuite = new Suite({
benchmarkMode: 'time' // Set mode for the entire suite
});
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
// Use minSamples: 1 for long-running operations to avoid redundant runs
timeSuite.add('Async Delay 100ms (time)', { minSamples: 1 }, async () => {
await delay(100);
});
timeSuite.add('Sync Busy Wait 50ms (time)', { minSamples: 1 }, () => {
const start = Date.now();
while (Date.now() - start < 50);
});
// repeatSuite runs multiple rounds; minSamples controls samples collected per round
timeSuite.add('Quick Sync Op with 5 repeats (time)', { repeatSuite: 5, minSamples: 1 }, () => {
let x = 1 + 1;
});
// Default minSamples (10) collects multiple independent measurements per round
timeSuite.add('Quick Sync Op with default minSamples (time)', () => {
let x = 1 + 1;
});
(async () => {
console.log('\nRunning benchmark suite in TIME mode...');
await timeSuite.run();
})();