Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Last active January 18, 2019 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Antoinebr/1274e1e81c02e51c37a7a87f08d4b42c to your computer and use it in GitHub Desktop.
Save Antoinebr/1274e1e81c02e51c37a7a87f08d4b42c to your computer and use it in GitHub Desktop.
const {
exec
} = require('child_process');
const {
promisify
} = require('util');
const execPromise = promisify(exec);
process.argv.splice(0, 2);
const [url, numOfmeasurement = 30, verbose = true] = process.argv;
let measurement = [];
let i = 0;
const getResult = () => {
const avg = measurement.reduce( (initial, mesurement) => initial+mesurement,0) / measurement.length
console.log(`\n\n${url} \n${i} measurements with an average TTFB of ${avg} seconds \n`);
};
process.on('SIGINT', getResult);
(async () => {
for (i ; i < parseInt(numOfmeasurement); i++) {
const responsefromCurl = await execPromise(`curl -s -L -o /dev/null -w %{time_starttransfer} ${url}`);
//await new Promise( (resolve, reject) => setTimeout( () => resolve(), 3000 ));
measurement.push(parseFloat(responsefromCurl.stdout))
if(verbose) console.log(responsefromCurl.stdout);
}
getResult();
})()
.catch(e => 'Error ' + e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment