dawen/dic-service-benchmark-bundle
Installation:
composer require dawen/dic-service-benchmark-bundle
No kernel registration is required—this is a zero-configuration package.
First Run: Execute the bundled test directly via PHPUnit (disable coverage for faster results):
./vendor/bin/phpunit -c app vendor/dawen/dic-service-benchmark-bundle/Tests/DicServiceBenchmarkTest.php
Outputs a list of registered services with their instantiation times.
Threshold Check: The test fails if any service exceeds 50ms by default. Useful for performance regression detection.
Performance Profiling:
./vendor/bin/phpunit -c app --filter=DicServiceBenchmarkTest
Ignoring Services:
phpunit.xml:
<php>
<var name="dic-service-benchmark-ignore" value="web_profiler.controller.router:my_ignored_service"/>
</php>
Custom Thresholds:
// tests/DicServiceBenchmarkCustomTest.php
use Dawen\Bundle\DicServiceBenchmarkBundle\Tests\DicServiceBenchmarkTest;
class CustomBenchmarkTest extends DicServiceBenchmarkTest {
protected $maxAllowedTime = 100; // ms
}
Integration with Laravel:
use Dawen\Bundle\DicServiceBenchmarkBundle\Service\BenchmarkService;
$benchmark = new BenchmarkService($container);
$results = $benchmark->run();
BenchmarkService to the container for reuse.False Positives:
dic-service-benchmark-ignore or adjust the threshold.Environment Dependencies:
Lazy Services:
App\Services\LazyService::class) may show inconsistent times.No Laravel-Specific Docs:
Illuminate\Container\Container as the DIC.BenchmarkService if not auto-discovered.Test Isolation:
run() method for debug logs (not exposed in README).@Lazy annotations (Symfony).microtime(true) or Xdebug.Custom Benchmark Logic:
Dawen\Bundle\DicServiceBenchmarkBundle\Service\BenchmarkService to:
class ExtendedBenchmarkService extends BenchmarkService {
public function run() {
$results = parent::run();
$this->logResults($results); // Custom logic
return $results;
}
}
Visualization:
Service: app.service.foo | Time: 12.34ms | Status: OK
Service: app.service.bar | Time: 67.89ms | Status: FAIL (threshold: 50ms)
Parallel Testing:
--parallel flag to speed up benchmarking across multiple services.How can I help you explore Laravel packages today?