0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 03:07:54 +01:00
nodejs/benchmark/es/eval.js
legendecas 02eb10b87b
lib,src: add source map support for global eval
Dynamic sources with FunctionConstructor is not supported yet as
V8 prepends lines to the sources which makes the stack line number
incorrect.

PR-URL: https://github.com/nodejs/node/pull/43428
Refs: https://github.com/nodejs/node/issues/43047
Reviewed-By: Ben Coe <bencoe@gmail.com>
2022-07-11 21:44:04 +08:00

47 lines
898 B
JavaScript

'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
method: ['without-sourcemap', 'sourcemap'],
n: [1e6],
});
const sourceWithoutSourceMap = `
'use strict';
(function() {
let a = 1;
for (let i = 0; i < 1000; i++) {
a++;
}
return a;
})();
`;
const sourceWithSourceMap = `
${sourceWithoutSourceMap}
//# sourceMappingURL=https://ci.nodejs.org/405
`;
function evalN(n, source) {
bench.start();
for (let i = 0; i < n; i++) {
eval(source);
}
bench.end(n);
}
function main({ n, method }) {
switch (method) {
case 'without-sourcemap':
process.setSourceMapsEnabled(false);
evalN(n, sourceWithoutSourceMap);
break;
case 'sourcemap':
process.setSourceMapsEnabled(true);
evalN(n, sourceWithSourceMap);
break;
default:
throw new Error(`Unexpected method "${method}"`);
}
}