11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// This benchmarks compiling scripts that hit the in-isolate compilation
41cb0ef41Sopenharmony_ci// cache (by having the same source).
51cb0ef41Sopenharmony_ciconst common = require('../common.js');
61cb0ef41Sopenharmony_ciconst fs = require('fs');
71cb0ef41Sopenharmony_ciconst vm = require('vm');
81cb0ef41Sopenharmony_ciconst fixtures = require('../../test/common/fixtures.js');
91cb0ef41Sopenharmony_ciconst scriptPath = fixtures.path('snapshot', 'typescript.js');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
121cb0ef41Sopenharmony_ci  type: ['with-dynamic-import-callback', 'without-dynamic-import-callback'],
131cb0ef41Sopenharmony_ci  n: [100],
141cb0ef41Sopenharmony_ci});
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst scriptSource = fs.readFileSync(scriptPath, 'utf8');
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cifunction main({ n, type }) {
191cb0ef41Sopenharmony_ci  let script;
201cb0ef41Sopenharmony_ci  bench.start();
211cb0ef41Sopenharmony_ci  const options = {};
221cb0ef41Sopenharmony_ci  switch (type) {
231cb0ef41Sopenharmony_ci    case 'with-dynamic-import-callback':
241cb0ef41Sopenharmony_ci      // Use a dummy callback for now until we really need to benchmark it.
251cb0ef41Sopenharmony_ci      options.importModuleDynamically = async () => {};
261cb0ef41Sopenharmony_ci      break;
271cb0ef41Sopenharmony_ci    case 'without-dynamic-import-callback':
281cb0ef41Sopenharmony_ci      break;
291cb0ef41Sopenharmony_ci  }
301cb0ef41Sopenharmony_ci  for (let i = 0; i < n; i++) {
311cb0ef41Sopenharmony_ci    script = new vm.Script(scriptSource, options);
321cb0ef41Sopenharmony_ci  }
331cb0ef41Sopenharmony_ci  bench.end(n);
341cb0ef41Sopenharmony_ci  script.runInThisContext();
351cb0ef41Sopenharmony_ci}
36