diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-04-03 15:43:32 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-04-03 15:45:57 +0200 |
commit | 71e285b94c7edaa43aa8115965cf5a36b8e0f80a (patch) | |
tree | 7d4aa9d0d5aff686b106cd5da72ba77960c4af43 /deps/node/benchmark/run.js | |
parent | 7dadf9356b4f3f4137ce982ea5bb960283116e9a (diff) | |
download | akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.gz akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.bz2 akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.zip |
Node.js v11.13.0
Diffstat (limited to 'deps/node/benchmark/run.js')
-rw-r--r-- | deps/node/benchmark/run.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/deps/node/benchmark/run.js b/deps/node/benchmark/run.js new file mode 100644 index 00000000..2eb1ab1a --- /dev/null +++ b/deps/node/benchmark/run.js @@ -0,0 +1,77 @@ +'use strict'; + +const path = require('path'); +const fork = require('child_process').fork; +const CLI = require('./_cli.js'); + +const cli = CLI(`usage: ./node run.js [options] [--] <category> ... + Run each benchmark in the <category> directory a single time, more than one + <category> directory can be specified. + + --filter pattern string to filter benchmark scripts + --set variable=value set benchmark variable (can be repeated) + --format [simple|csv] optional value that specifies the output format +`, { arrayArgs: ['set'] }); +const benchmarks = cli.benchmarks(); + +if (benchmarks.length === 0) { + console.error('No benchmarks found'); + process.exitCode = 1; + return; +} + +const validFormats = ['csv', 'simple']; +const format = cli.optional.format || 'simple'; +if (!validFormats.includes(format)) { + console.error('Invalid format detected'); + process.exitCode = 1; + return; +} + +if (format === 'csv') { + console.log('"filename", "configuration", "rate", "time"'); +} + +(function recursive(i) { + const filename = benchmarks[i]; + const child = fork(path.resolve(__dirname, filename), cli.optional.set); + + if (format !== 'csv') { + console.log(); + console.log(filename); + } + + child.on('message', (data) => { + if (data.type !== 'report') { + return; + } + // Construct configuration string, " A=a, B=b, ..." + let conf = ''; + for (const key of Object.keys(data.conf)) { + conf += ` ${key}=${JSON.stringify(data.conf[key])}`; + } + // Delete first space of the configuration + conf = conf.slice(1); + if (format === 'csv') { + // Escape quotes (") for correct csv formatting + conf = conf.replace(/"/g, '""'); + console.log(`"${data.name}", "${conf}", ${data.rate}, ${data.time}`); + } else { + var rate = data.rate.toString().split('.'); + rate[0] = rate[0].replace(/(\d)(?=(?:\d\d\d)+(?!\d))/g, '$1,'); + rate = (rate[1] ? rate.join('.') : rate[0]); + console.log(`${data.name} ${conf}: ${rate}`); + } + }); + + child.once('close', (code) => { + if (code) { + process.exit(code); + } + + // If there are more benchmarks execute the next + if (i + 1 < benchmarks.length) { + recursive(i + 1); + } + }); +})(0); |