Skip to content

Instantly share code, notes, and snippets.

@rodmcnew
Last active July 19, 2016 16:57
Show Gist options
  • Save rodmcnew/45202b1401fdb6ebe51d9cda6c643776 to your computer and use it in GitHub Desktop.
Save rodmcnew/45202b1401fdb6ebe51d9cda6c643776 to your computer and use it in GitHub Desktop.
repeat.js
var exec = require('child_process').exec;
var cmd = process.argv[2];
console.log(' - - - ');
console.log('Running the following command repeatedly:');
console.log(cmd);
var count = 0;
var averageSumTime = 0;
var averageTime = 0;
function tick() {
count++;
var paddedCount = "0000000000" + count;
paddedCount = paddedCount.substr(paddedCount.length - 10);
var start = new Date().getTime();
exec(cmd, function (error, stdout, stderr) {
var end = new Date().getTime();
var time = end - start;
var message = 'Success';
if (error) {
message = stderr;
}
averageSumTime += time;
averageTime = Math.round(averageSumTime / count);
console.log(paddedCount, time + 'ms', message, '(' + averageTime + 'ms average)');
if (!error) {
tick()
}
});
}
tick();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment