windwalker / profiler
Windwalker Profiler package
Installs: 52
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 0
Open Issues: 0
Type:windwalker-package
Requires
- php: >=7.1.3
Requires (Dev)
- windwalker/test: ~3.0
- 3.x-dev
- 3.5.23
- 3.5.22
- 3.5.21
- 3.5.20
- 3.5.19
- 3.5.18
- 3.5.17
- 3.5.16
- 3.5.15
- 3.5.14
- 3.5.13
- 3.5.12
- 3.5.11
- 3.5.10
- 3.5.9
- 3.5.8
- 3.5.7
- 3.5.6
- 3.5.5
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5
- 3.4.9
- 3.4.8
- 3.4.7
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4
- 3.3.2
- 3.3.1
- 3.3
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2
- 3.1.6
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1
- 3.0.1
- 3.0
- 3.0-beta2
- 3.0-beta
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.2
- 2.1.1
- 2.1
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-beta2
- 2.0.0-beta1
- 2.0.0-alpha
- dev-test
This package is auto-updated.
Last update: 2024-10-18 14:30:58 UTC
README
Windwalker Profiler can help us profiler some process information for debug.
Installation via Composer
Add this to the require block in your composer.json
.
{ "require": { "windwalker/profiler": "~3.0" } }
Create A Profiler And Mark A Point
use Windwalker\Profiler\Profiler; $profiler = new Profiler; $profiler->mark('StartRender'); // Execute some code... $profiler->mark('AfterRender'); // Execute some code... $profiler->mark('End');
Now your can get the elapsed time between two points:
$profiler->getTimeBetween('StartRender', 'AfterRender');
Or get memory amount between two points:
// Return memory bytes $profiler->getMemoryBetween('StartRender', 'AfterRender');
Output Result
echo $profiler->render();
Notes 0.000 seconds (+0.000); 0.00 MB (+0.000) - StartRender Notes 1.000 seconds (+1.000); 3.00 MB (+3.000) - AfterRender Notes 1.813 seconds (+0.813); 6.24 MB (+3.240) - End
Benchmark
Benchmark is a convenience object to test two or more tasks executing time.
use Windwalker\Profiler\Banchmark; $benchmark = new Benchmark; $benchmark->addTask('task1', function() { md5(uniqid()); }) ->addTask('task2', function() { sha1(uniqid()); }); $benchmark->execute(10000); echo $benchmark->render();
The output
task1 => 0.204897 s
task2 => 0.205108 s
Use Other format
$benchmark->setTimeFormat(Benchmark::MILLI_SECOND)->execute(10000); echo $benchmark->render(); /* Result task1 => 187.489986 ms task2 => 207.049847 ms */
$benchmark->setTimeFormat(Benchmark::MICRO_SECOND)->execute(10000); echo $benchmark->render(); /* Result task1 => 198050.9758 μs task2 => 206343.173981 μs */
Custom Render Handler
$benchmark->setRenderOneHandler(function($name, $result, $round, $format) { return $name . ' : ' . round($result, $round); }); $benchmark->render();