PHP code example of kaniosx / phpunit-performance-profiler
1. Go to this page and download the library: Download kaniosx/phpunit-performance-profiler library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kaniosx / phpunit-performance-profiler example snippets
use Kaniosx\PhpunitPerformanceProfiler\AssertsPerformance;
use PHPUnit\Framework\TestCase;
final class ReportGeneratorTest extends TestCase
{
use AssertsPerformance;
public function testGeneratingTheReportStaysWithinTheMemoryBudget(): void
{
$this->assertMemoryPeakUnder(64, function (): void {
(new ReportGenerator())->generate();
});
}
public function testGeneratingTheReportStaysWithinTheTimeBudget(): void
{
$this->assertExecutionTimeUnder(200, function (): void {
(new ReportGenerator())->generate();
});
}
}
use Kaniosx\PhpunitPerformanceProfiler\Profiler;
$result = Profiler::run(function (): void {
(new ReportGenerator())->generate();
});
echo $result->getFormattedDuration(); // e.g. "12.345 ms"
echo $result->getFormattedMemoryPeak(); // e.g. "3.42 MB"