Running Benchmarks
How to run performance benchmarks.
Introduction
Section titled “Introduction”Data Helpers uses PHPBench for performance benchmarking.
Running Benchmarks
Section titled “Running Benchmarks”Run All Benchmarks
Section titled “Run All Benchmarks”composer benchmarkRun Specific Benchmark
Section titled “Run Specific Benchmark”vendor/bin/phpbench run benchmarks/DataAccessorBench.phpCreate Baseline
Section titled “Create Baseline”composer benchmark:baselineCompare Against Baseline
Section titled “Compare Against Baseline”composer benchmark:compareAvailable Benchmarks
Section titled “Available Benchmarks”- DataAccessor - Get operations
- DataMutator - Set/merge operations
- DataMapper - Mapping operations
- SimpleDTO - DTO creation, validation, serialization
Creating Custom Benchmarks
Section titled “Creating Custom Benchmarks”<?php
namespace event4u\DataHelpers\Benchmarks;
use PhpBench\Attributes\BeforeMethods;use PhpBench\Attributes\Iterations;use PhpBench\Attributes\Revs;
#[BeforeMethods('setUp')]class MyBench{ private array $data;
public function setUp(): void { $this->data = ['key' => 'value']; }
#[Revs(1000)] #[Iterations(5)] public function benchMyOperation(): void { // Code to benchmark }}Interpreting Results
Section titled “Interpreting Results”Average time per operation:
mode: 0.5μs // 0.5 microsecondsRStdev
Section titled “RStdev”Relative standard deviation:
rstdev: 2.5% // 2.5% variationLower is better.
Best Practices
Section titled “Best Practices”Disable Xdebug
Section titled “Disable Xdebug”php -d xdebug.mode=off vendor/bin/phpbench runUse Baseline
Section titled “Use Baseline”composer benchmark:baseline# Make changescomposer benchmark:compareSee Also
Section titled “See Also”- Performance Benchmarks - Results
- Optimization - Optimization guide