forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.js
More file actions
46 lines (41 loc) · 898 Bytes
/
eval.js
File metadata and controls
46 lines (41 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'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}"`);
}
}