Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bench-eventlooputil.js « perf_hooks « benchmark - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 984b2b66aecbcf04beaef849eb09f4d61da1f69f (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';

const common = require('../common.js');
const assert = require('assert').ok;
const { performance } = require('perf_hooks');
const { nodeTiming, eventLoopUtilization } = performance;

const bench = common.createBenchmark(main, {
  n: [1e6],
  method: [
    'idleTime',
    'ELU_simple',
    'ELU_passed',
  ],
});

function main({ method, n }) {
  switch (method) {
    case 'idleTime':
      benchIdleTime(n);
      break;
    case 'ELU_simple':
      benchELUSimple(n);
      break;
    case 'ELU_passed':
      benchELUPassed(n);
      break;
    default:
      throw new Error(`Unsupported method ${method}`);
  }
}

function benchIdleTime(n) {
  bench.start();
  for (let i = 0; i < n; i++)
    nodeTiming.idleTime;
  bench.end(n);
}

function benchELUSimple(n) {
  // Need to put this in setImmediate or will always return 0.
  setImmediate(() => {
    const elu = eventLoopUtilization();
    assert(elu.active + elu.idle > 0);

    bench.start();
    for (let i = 0; i < n; i++)
      eventLoopUtilization();
    bench.end(n);
  });
}

function benchELUPassed(n) {
  // Need to put this in setImmediate or will always return 0.
  setImmediate(() => {
    let elu = eventLoopUtilization();
    assert(elu.active + elu.idle > 0);

    bench.start();
    for (let i = 0; i < n; i++)
      elu = eventLoopUtilization(elu);
    bench.end(n);
  });
}