alecrabbit / php-simple-profiler
此包已被弃用,不再维护。未建议替换包。
用于功能基准测试,包含计数器和计时器类。
0.20.1-ALPHA.1
2019-07-25 10:37 UTC
Requires
- php: ^7.2
- alecrabbit/php-accessories: ^0.9
- alecrabbit/php-console-colour: ^0.5
- alecrabbit/php-console-spinner: ^0.14
- alecrabbit/php-counters: ^0.2
- alecrabbit/php-helpers: ^0.6
- alecrabbit/php-reports: ^0.2
- alecrabbit/php-timers: ^0.1
- alecrabbit/php-traits: ^0.3
- sebastian/exporter: ^3.1
Requires (Dev)
- krowinski/bcmath-extended: ^4.2 || ^5.0
- nunomaduro/collision: ^3.0
- php-mock/php-mock-phpunit: ^2.4
- phpunit/phpunit: ^8.0
- symfony/console: ^4.3
- symfony/phpunit-bridge: ^4.3
- symfony/var-dumper: ^4.3
Suggests
- symfony/console: To use symfony progress bar and colored output.
This package is auto-updated.
Last update: 2021-07-10 16:17:39 UTC
README
演示
查看演示
快速开始
基准测试
use AlecRabbit\Tools\BenchmarkSymfonyProgressBar; require_once __DIR__ . '/vendor/autoload.php'; $benchmark = new BenchmarkSymfonyProgressBar(900000); $benchmark ->addFunction('hrtime', true); $benchmark ->addFunction('microtime', true); echo $benchmark->run()->noReturns()->report() . PHP_EOL; echo $benchmark->stat() . PHP_EOL;
输出将类似于
Results:
Benchmark:
1. 150.1ns ( 0.00%) ⟨1⟩ hrtime(boolean)
2. 157.7ns ( 5.07%) ⟨2⟩ microtime(boolean)
Benchmarked: 2
Memory: 0.88MB(0.92MB) Real: 2.00MB(2.00MB)
Done in: 2.0s
更多信息请参阅示例
注意:某些示例可能不是最新的... 进行中
进行中
安装
目前建议在开发过程中使用此包
composer require --dev alecrabbit/php-simple-profiler
或者
composer require alecrabbit/php-simple-profiler
基准测试类
有时候你需要从两种或更多不同的方法中选择。基准测试类可以帮助你选择哪种更快 :)
Benchmark::class
(无默认进度条,静默测量)BenchmarkSymfonyPB::class
(带有Symfony进度条)
26% [████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 1 sec/4 secs
BenchmarkSimplePB::class
(带有星形进度条)
******************************
示例
假设你想知道哪个更快:call_user_func($func)
还是 $func()
。首先你需要创建一个基准测试类的实例
$b = new BenchmarkSymfonyPB(900000) // with Symfony Progress bar, 900000 measurments
然后你需要添加要测试的函数。但首先让我们添加一个闭包
$func = function (array $a) { return array_sum($a); };
现在我们准备好添加函数
$a = [1, 2, 3]; $b->addFunction('call_user_func', $func, $a); $b->addFunction($func, $a);
现在你可以运行基准测试
$b->run();
获取结果
$report = $b->report(); // you can get report object and use data from it echo $report . PHP_EOL; // or you can print it by default formatter echo $b->stat() . PHP_EOL;
结果将类似于这样
Results:
Benchmark:
1. 219.3ns ( 0.00%) $func(array) $func(...$args)
2. 287.4ns ( 31.09%) call_user_func(array) \call_user_func($func, ...$args)
All returns are equal:
integer(6)
Benchmarked: 2
Memory: 0.87MB(0.91MB) Real: 2.00MB(2.00MB)
Done in: 1.1s
Profiler::class
Profiler是一种包装Counter和Timer的类,如果你需要同时使用它们。
$profiler = new Profiler(); for ($i = 0; $i < 100; $i++) { $profiler->counter()->bump(); someOperation(); $profiler->timer()->check(); } echo $profiler->report() . PHP_EOL;
Counter::class
// todo
Timer::class
// todo