forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathload-native.js
More file actions
32 lines (29 loc) · 929 Bytes
/
load-native.js
File metadata and controls
32 lines (29 loc) · 929 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
'use strict';
const path = require('path');
// Use an absolute path as the old loader was faster using an absolute path.
const commonPath = path.resolve(__dirname, '../common.js');
const common = require(commonPath);
const bench = common.createBenchmark(main, {
n: [1000],
useCache: ['true', 'false']
});
function main({ n, useCache }) {
const natives = [
'vm', 'util', 'child_process', 'dns', 'querystring', 'http', 'process',
'http2', 'net', 'os', 'buffer', 'crypto', 'url', 'path', 'string_decoder'
];
if (useCache) {
for (const name of natives)
require(name);
require(commonPath);
}
bench.start();
for (var i = 0; i < n; i++) {
for (var j = 0; j < natives.length; j++)
require(natives[j]);
// Pretend mixed input (otherwise the results are less representative due to
// highly specialized code).
require(commonPath);
}
bench.end(n * (natives.length + 1));
}