1'use strict';
2
3// This benchmarks compiling scripts that hit the in-isolate compilation
4// cache (by having the same source).
5const common = require('../common.js');
6const fs = require('fs');
7const vm = require('vm');
8const fixtures = require('../../test/common/fixtures.js');
9const scriptPath = fixtures.path('snapshot', 'typescript.js');
10
11const bench = common.createBenchmark(main, {
12  type: ['with-dynamic-import-callback', 'without-dynamic-import-callback'],
13  n: [100],
14});
15
16const scriptSource = fs.readFileSync(scriptPath, 'utf8');
17
18function main({ n, type }) {
19  let script;
20  bench.start();
21  const options = {};
22  switch (type) {
23    case 'with-dynamic-import-callback':
24      // Use a dummy callback for now until we really need to benchmark it.
25      options.importModuleDynamically = async () => {};
26      break;
27    case 'without-dynamic-import-callback':
28      break;
29  }
30  for (let i = 0; i < n; i++) {
31    script = new vm.Script(scriptSource, options);
32  }
33  bench.end(n);
34  script.runInThisContext();
35}
36