Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
benchmark: add module loader benchmark parameter
PR-URL: #5172
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
mscdex committed Apr 14, 2016
commit 1e4674ae0aec78f32c26a297ac11b45d46c24344
21 changes: 17 additions & 4 deletions benchmark/module/module-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ var tmpDirectory = path.join(__dirname, '..', 'tmp');
var benchmarkDirectory = path.join(tmpDirectory, 'nodejs-benchmark-module');

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

function main(conf) {
var n = +conf.thousands * 1e3;

rmrf(tmpDirectory);
try { fs.mkdirSync(tmpDirectory); } catch (e) {}
try { fs.mkdirSync(benchmarkDirectory); } catch (e) {}

var n = +conf.thousands * 1e3;
for (var i = 0; i <= n; i++) {
fs.mkdirSync(benchmarkDirectory + i);
fs.writeFileSync(
Expand All @@ -28,10 +30,21 @@ function main(conf) {
);
}

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

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

function measure(n) {
function measureDir(n) {
bench.start();
for (var i = 0; i <= n; i++) {
require(benchmarkDirectory + i);
Expand Down