summaryrefslogtreecommitdiff
path: root/benchmark/module/module-loader-circular.js
blob: 0d4f1043ced07d7348aae3f5a0fc688a7453f75d (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
'use strict';
const fs = require('fs');
const path = require('path');
const common = require('../common.js');

const tmpdir = require('../../test/common/tmpdir');
const benchmarkDirectory =
  path.resolve(tmpdir.path, 'benchmark-module-circular');

const bench = common.createBenchmark(main, {
  n: [1e4],
});

function main({ n }) {
  tmpdir.refresh();

  const aDotJS = path.join(benchmarkDirectory, 'a.js');
  const bDotJS = path.join(benchmarkDirectory, 'b.js');

  fs.mkdirSync(benchmarkDirectory);
  fs.writeFileSync(aDotJS, 'require("./b.js");');
  fs.writeFileSync(bDotJS, 'require("./a.js");');

  bench.start();
  for (let i = 0; i < n; i++) {
    require(aDotJS);
    require(bDotJS);
    delete require.cache[aDotJS];
    delete require.cache[bDotJS];
  }
  bench.end(n);

  tmpdir.refresh();
}