• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const fs = require('fs');
3const path = require('path');
4const common = require('../common.js');
5
6const tmpdir = require('../../test/common/tmpdir');
7const benchmarkDirectory =
8  path.resolve(tmpdir.path, 'benchmark-module-circular');
9
10const bench = common.createBenchmark(main, {
11  n: [1e4]
12});
13
14function main({ n }) {
15  tmpdir.refresh();
16
17  const aDotJS = path.join(benchmarkDirectory, 'a.js');
18  const bDotJS = path.join(benchmarkDirectory, 'b.js');
19
20  fs.mkdirSync(benchmarkDirectory);
21  fs.writeFileSync(aDotJS, 'require("./b.js");');
22  fs.writeFileSync(bDotJS, 'require("./a.js");');
23
24  bench.start();
25  for (let i = 0; i < n; i++) {
26    require(aDotJS);
27    require(bDotJS);
28    delete require.cache[aDotJS];
29    delete require.cache[bDotJS];
30  }
31  bench.end(n);
32
33  tmpdir.refresh();
34}
35