Skip to content

Commit

Permalink
benchmark: add parameter for module benchmark
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mscdex committed Mar 11, 2017
1 parent 99b27ce commit 190dc69
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions benchmark/module/module-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var benchmarkDirectory = path.join(tmpDirectory, 'nodejs-benchmark-module');

var bench = common.createBenchmark(main, {
thousands: [50],
fullPath: ['true', 'false']
fullPath: ['true', 'false'],
useCache: ['true', 'false']
});

function main(conf) {
Expand All @@ -31,22 +32,34 @@ function main(conf) {
}

if (conf.fullPath === 'true')
measureFull(n);
measureFull(n, conf.useCache === 'true');
else
measureDir(n);
measureDir(n, conf.useCache === 'true');
}

function measureFull(n) {
function measureFull(n, useCache) {
var i;
if (useCache) {
for (i = 0; i <= n; i++) {
require(benchmarkDirectory + i + '/index.js');
}
}
bench.start();
for (var i = 0; i <= n; i++) {
for (i = 0; i <= n; i++) {
require(benchmarkDirectory + i + '/index.js');
}
bench.end(n / 1e3);
}

function measureDir(n) {
function measureDir(n, useCache) {
var i;
if (useCache) {
for (i = 0; i <= n; i++) {
require(benchmarkDirectory + i);
}
}
bench.start();
for (var i = 0; i <= n; i++) {
for (i = 0; i <= n; i++) {
require(benchmarkDirectory + i);
}
bench.end(n / 1e3);
Expand Down

0 comments on commit 190dc69

Please sign in to comment.