1'use strict'; 2 3const common = require('../common.js'); 4 5const bench = common.createBenchmark(main, { 6 method: ['without-sourcemap', 'sourcemap'], 7 n: [1e6], 8}); 9 10const sourceWithoutSourceMap = ` 11'use strict'; 12(function() { 13 let a = 1; 14 for (let i = 0; i < 1000; i++) { 15 a++; 16 } 17 return a; 18})(); 19`; 20const sourceWithSourceMap = ` 21${sourceWithoutSourceMap} 22//# sourceMappingURL=https://ci.nodejs.org/405 23`; 24 25function evalN(n, source) { 26 bench.start(); 27 for (let i = 0; i < n; i++) { 28 eval(source); 29 } 30 bench.end(n); 31} 32 33function main({ n, method }) { 34 switch (method) { 35 case 'without-sourcemap': 36 process.setSourceMapsEnabled(false); 37 evalN(n, sourceWithoutSourceMap); 38 break; 39 case 'sourcemap': 40 process.setSourceMapsEnabled(true); 41 evalN(n, sourceWithSourceMap); 42 break; 43 default: 44 throw new Error(`Unexpected method "${method}"`); 45 } 46} 47