38618406340ca8f11b5ce4162bf7fd4086e071e1

Author: Mark Story

Date: 2008-12-06 23:20:58 -0500

Added -n and -t to benchmark shell. These params emulate Apache AB tester.

diff --git a/vendors/shells/benchmark.php b/vendors/shells/benchmark.php index 5ad5b7a..bac6d68 100644 --- a/vendors/shells/benchmark.php +++ b/vendors/shells/benchmark.php @@ -32,13 +32,48 @@ class BenchmarkShell extends Shell { $this->out(sprintf('-> Testing %s', $url)); $n = 100; + $t = $i = 0; + if (isset($this->params['n'])) { + $n = $this->params['n']; + } + if (isset($this->params['t'])) { + $t = $this->params['t']; + } $start = microtime(true); - for ($i = 0; $i < $n; $i++) { + while (true) { + if ($t && $t <= floor(microtime(true) - $start)) { + break; + } + if ($n <= $i) { + break; + } file_get_contents($url); + $i++; } $duration = microtime(true) - $start; + $this->out('Total Requests made: ' . $i); + $this->out('Total Time elapsed: ' . $duration . '(s)'); $this->out(round($n / $duration, 2).' req/sec'); } + + function help() { + $out = <<<EOL + DebugKit Benchmark Shell + + Test a fully qualified url to get avg requests per second. + By default it does 100 requests to the provided url. + + Use: + cake benchmark [params] [url] + + Params + -n The maximum number of iterations to do. + + -t The maximum time to take. If a single request takes more + than this time. Only one request will be made. +EOL; + $this->out($out); + } } ?> \ No newline at end of file