Skip to content

Commit 190dc69

Browse files
committed
benchmark: add parameter for module benchmark
PR-URL: #10789 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 99b27ce commit 190dc69

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

benchmark/module/module-loader.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ var benchmarkDirectory = path.join(tmpDirectory, 'nodejs-benchmark-module');
88

99
var bench = common.createBenchmark(main, {
1010
thousands: [50],
11-
fullPath: ['true', 'false']
11+
fullPath: ['true', 'false'],
12+
useCache: ['true', 'false']
1213
});
1314

1415
function main(conf) {
@@ -31,22 +32,34 @@ function main(conf) {
3132
}
3233

3334
if (conf.fullPath === 'true')
34-
measureFull(n);
35+
measureFull(n, conf.useCache === 'true');
3536
else
36-
measureDir(n);
37+
measureDir(n, conf.useCache === 'true');
3738
}
3839

39-
function measureFull(n) {
40+
function measureFull(n, useCache) {
41+
var i;
42+
if (useCache) {
43+
for (i = 0; i <= n; i++) {
44+
require(benchmarkDirectory + i + '/index.js');
45+
}
46+
}
4047
bench.start();
41-
for (var i = 0; i <= n; i++) {
48+
for (i = 0; i <= n; i++) {
4249
require(benchmarkDirectory + i + '/index.js');
4350
}
4451
bench.end(n / 1e3);
4552
}
4653

47-
function measureDir(n) {
54+
function measureDir(n, useCache) {
55+
var i;
56+
if (useCache) {
57+
for (i = 0; i <= n; i++) {
58+
require(benchmarkDirectory + i);
59+
}
60+
}
4861
bench.start();
49-
for (var i = 0; i <= n; i++) {
62+
for (i = 0; i <= n; i++) {
5063
require(benchmarkDirectory + i);
5164
}
5265
bench.end(n / 1e3);

0 commit comments

Comments
 (0)