Download the PHP package dragon-code/runtime-comparison without Composer
On this page you can find all versions of the php package dragon-code/runtime-comparison. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dragon-code/runtime-comparison
More information about dragon-code/runtime-comparison
Files in dragon-code/runtime-comparison
Package runtime-comparison
Short Description Simple comparison of execution time of different code
License MIT
Informations about the package runtime-comparison
Benchmark
Installation
Usage
[!NOTE]
When more than 9 iterations are used, the top and bottom 10% of results are excluded from the average calculation, producing cleaner data less dependent on external factors.
You can use both the bench() helper function and the Benchmark class (new Benchmark() or Benchmark::make()).
Callbacks can be passed as an array or as arguments, with or without named keys:
Example output:
Iterations Count
By default, the benchmark performs 100 iterations per callback. Use the iterations method to change this.
The current iteration number is available as a callback parameter:
Warm-up
Use the warmup method to run each callback a few times before the measured iterations. Warm-up runs behave
identically to regular ones (beforeEach / afterEach are invoked, the progress bar advances), but their
time and memory are not included in the final statistics.
This stabilizes results by absorbing one-time costs such as cold caches, JIT/opcache priming and lazy autoloading.
Disabled by default.
Round Precision
Use the round method to set the number of decimal places in console output:
Deviation Values
Use the deviations method to measure the deviation between results. All loops will repeat the specified number of
times, and the output will include a deviation row:
Callbacks
You can register callbacks to run before/after the entire benchmark loop or before/after each iteration:
The result of beforeEach is passed to the compare callback:
Results
toConsole
Outputs results to the console:
With deviation values:
toData
Returns results as an array of DragonCode\Benchmark\Data\ResultData DTO objects:
toAssert
Validates benchmark results against expected thresholds. Both from and till parameters are optional — use one or both:
Regression Testing
Detects performance regressions by comparing current results to a saved baseline (snapshot).
How To Work
- First run: no
.snapfiles exist — results are written to disk, no check is performed. - Next runs: results are compared to the snapshot; exceeding
$maxpercent throws anAssertionError. - Location: snapshots are stored per call site (subdirectory derived from the caller file and line).
[!NOTE]
Delete the corresponding
.snapfiles to reset the baseline — the next run will recreate them.
Configuring the Snapshot Directory
Set the snapshot directory via snapshots(). Default: ./.benchmarks.
[!TIP]
Commit the generated snapshot files to version control to keep regression checks consistent across environments and CI.
toBeRegressionTime
Fails if execution time exceeds the snapshot by more than $max percent.
toBeRegressionMemory
Fails if memory usage exceeds the snapshot by more than $max percent.
Disable Progress Bar
License
This package is licensed under the MIT License.