benchmark: add filter option for benchmark

Before:

    # common.js executes all tests in net directory.
    $ ./iojs common.js net

After:

    # common.js executes only "dgram" tests in net directory.
    $ ./iojs common.js net dgram

PR-URL: https://github.com/iojs/io.js/pull/488
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Yosuke Furukawa 2015-01-18 00:33:07 +09:00 committed by Ben Noordhuis
parent 4764eef9b2
commit ea7750bddd

View File

@ -7,8 +7,9 @@ exports.PORT = process.env.PORT || 12346;
// If this is the main module, then run the benchmarks // If this is the main module, then run the benchmarks
if (module === require.main) { if (module === require.main) {
var type = process.argv[2]; var type = process.argv[2];
var testFilter = process.argv[3];
if (!type) { if (!type) {
console.error('usage:\n ./iojs benchmark/common.js <type>'); console.error('usage:\n ./iojs benchmark/common.js <type> [testFilter]');
process.exit(1); process.exit(1);
} }
@ -17,6 +18,19 @@ if (module === require.main) {
var tests = fs.readdirSync(dir); var tests = fs.readdirSync(dir);
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
if (testFilter) {
var filteredTests = tests.filter(function(item){
if (item.lastIndexOf(testFilter) >= 0) {
return item;
}
});
if (filteredTests.length === 0) {
console.error(`${testFilter} is not found in \n ${tests.join(' \n')}`);
return;
}
tests = filteredTests;
}
runBenchmarks(); runBenchmarks();
} }