Skip to content

Running Benchmarks

How to run performance benchmarks.

Data Helpers uses PHPBench for performance benchmarking.

Terminal window
composer benchmark
Terminal window
vendor/bin/phpbench run benchmarks/DataAccessorBench.php
Terminal window
composer benchmark:baseline
Terminal window
composer benchmark:compare
  • DataAccessor - Get operations
  • DataMutator - Set/merge operations
  • DataMapper - Mapping operations
  • SimpleDTO - DTO creation, validation, serialization
<?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
}
}

Average time per operation:

mode: 0.5μs // 0.5 microseconds

Relative standard deviation:

rstdev: 2.5% // 2.5% variation

Lower is better.

Terminal window
php -d xdebug.mode=off vendor/bin/phpbench run
Terminal window
composer benchmark:baseline
# Make changes
composer benchmark:compare