Skip to content

Instantly share code, notes, and snippets.

@dersam
Last active September 23, 2016 14:12
Show Gist options
  • Save dersam/95d13721dee1165f0c2c52856d7de40d to your computer and use it in GitHub Desktop.
Save dersam/95d13721dee1165f0c2c52856d7de40d to your computer and use it in GitHub Desktop.
Rudimentary response time tester
#!/usr/bin/php
<?php
if (!isset($argv[1])) {
die('No url provided.');
}
$cmd = "wget {$argv[1]} --no-check-certificate --delete-after -q --output-document=/dev/null";
$avg = 0;
$iterations = 10;
$max = 0;
$min = null;
for ($i =0; $i < $iterations; $i++) {
echo '.';
$start = microtime(true);
shell_exec($cmd);
$end = microtime(true);
$time = ($end - $start);
$avg += $time;
$max = $max < $time ? $time : $max;
$min = $min == null || $min > $time ? $time : $min;
}
echo PHP_EOL;
echo 'Average: '.number_format(($avg/$iterations)*1000, 0).'ms'.PHP_EOL;
echo 'Max: '.number_format($max*1000, 0).'ms'.PHP_EOL;
echo 'Min: '.number_format($min*1000, 0).'ms'.PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment