alexpw / timer
此包的最新版本(0.0.1)没有可用的许可信息。
0.0.1
2014-09-13 19:39 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-24 02:39:14 UTC
README
一个快速编写且易于使用的PHP计时器,用于基准测试。
用法
require 'vendor/autoload.php'; use Alexpw\Timer\Timer; $t = new Timer; $max = 500000; $xs = range(1, $max); $odd = function ($x) { return $x % 2 === 1; }; function isOdd($x) { return $x % 2 === 1; } $rs = array(); $run = $t->start("odd? control"); foreach ($xs as $x) { if ($x % 2 === 1) { $rs[] = $x; } } $t->end($run); $rs = array(); // use the gap between runs to teardown/setup $run = $t->start("odd? closure"); foreach ($xs as $x) { if ($odd($x)) { $rs[] = $x; } } $t->end($run); $rs = array(); $run = $t->start("odd? function"); foreach ($xs as $x) { if (isOdd($x)) { $rs[] = $x; } } $t->end($run); $rs = array(); $run = $t->start("odd? array_filter closure"); $rs = array_filter($xs, $odd); $t->end($run); $rs = array(); $run = $t->start("odd? array_filter function"); $rs = array_filter($xs, 'isOdd'); $t->end($run); unset($rs); echo $t->render();
示例输出
label time (ms) perc mem
------------------------------------------------------------------------------
odd? control 71.5 11.90 22.98 MB
odd? closure 131.3 21.85 22.98 MB
odd? function 123.9 20.62 22.98 MB
odd? array_filter closure 125.9 20.95 22.98 MB
odd? array_filter function 151.6 25.22 22.98 MB
------------------------------------------------------------------------------
时间
许可
MIT许可证下发布 - 详细信息请参阅LICENSE文件