Last active
July 19, 2016 16:57
-
-
Save rodmcnew/45202b1401fdb6ebe51d9cda6c643776 to your computer and use it in GitHub Desktop.
repeat.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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