-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (39 loc) · 1.09 KB
/
index.js
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
47
48
49
50
51
const { readFileSync } = require('fs');
const { Script, compileFunction } = require('vm');
const fileSource = readFileSync('./.yarn/releases/yarn-berry.cjs', 'utf8')
.split('\n')
// get rid of shebang
.slice(1)
.join('\n');
const oneMillisecondAsNano = 1_000_000n;
let start = process.hrtime.bigint();
for (let i = 0; i < 100; i++) {
new Script(fileSource);
}
console.log(
'Running with Script took',
Number((process.hrtime.bigint() - start) / oneMillisecondAsNano),
'ms',
);
start = process.hrtime.bigint();
for (let i = 0; i < 100; i++) {
compileFunction(fileSource);
}
console.log(
'Running with compileFunction took',
Number((process.hrtime.bigint() - start) / oneMillisecondAsNano),
'ms',
);
start = process.hrtime.bigint();
let cachedData;
for (let i = 0; i < 100; i++) {
const func = compileFunction(fileSource, [], {produceCachedData: true, cachedData});
if (!cachedData) {
cachedData = func.cachedData
}
}
console.log(
'Running with compileFunction and cached data took',
Number((process.hrtime.bigint() - start) / oneMillisecondAsNano),
'ms',
);