• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5
6const bench = common.createBenchmark(main, {
7  n: [1e6],
8  type: ['raw', 'diff', 'bigint']
9});
10
11function main({ n, type }) {
12  const hrtime = process.hrtime;
13  let noDead = type === 'bigint' ? hrtime.bigint() : hrtime();
14
15  switch (type) {
16    case 'raw':
17      bench.start();
18      for (let i = 0; i < n; i++) {
19        noDead = hrtime();
20      }
21      bench.end(n);
22      break;
23    case 'diff':
24      bench.start();
25      for (let i = 0; i < n; i++) {
26        noDead = hrtime(noDead);
27      }
28      bench.end(n);
29      break;
30    case 'bigint':
31      bench.start();
32      for (let i = 0; i < n; i++) {
33        noDead = hrtime.bigint();
34      }
35      bench.end(n);
36      break;
37  }
38
39  assert.ok(Array.isArray(noDead) || typeof noDead === 'bigint');
40}
41