Download the PHP package philiprehberger/php-stopwatch without Composer
On this page you can find all versions of the php package philiprehberger/php-stopwatch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download philiprehberger/php-stopwatch
More information about philiprehberger/php-stopwatch
Files in philiprehberger/php-stopwatch
Package php-stopwatch
Short Description Precise code execution timer with lap tracking and memory measurement
License MIT
Homepage https://github.com/philiprehberger/php-stopwatch
Informations about the package php-stopwatch
PHP Stopwatch
Precise code execution timer with lap tracking and memory measurement.
Requirements
- PHP 8.2+
Installation
Usage
Quick measurement
Measurement with return value
Manual start/stop with laps
Check elapsed time while running
Pause and resume
Nested stopwatches
Benchmark comparisons
Threshold alerts
Comparison reports
Profiling decorator
Statistical analysis
API
| Method | Returns | Description |
|---|---|---|
Stopwatch::start(?string $name) |
RunningStopwatch |
Start a new stopwatch with an optional name |
Stopwatch::measure(callable $fn) |
MeasureResult |
Measure execution time and memory of a callable |
Stopwatch::measureWithResult(callable $fn) |
array{result, measure} |
Measure while preserving the return value |
Stopwatch::benchmark(array $callables, int $iterations) |
BenchmarkResult |
Run each callable N times and compare performance |
Stopwatch::measureWithThreshold(callable, float, callable) |
MeasureResult |
Measure and fire callback if threshold exceeded |
Stopwatch::compare(array $benchmarks, int $iterations) |
ComparisonReport |
Compare named callables with rankings and ASCII table |
Stopwatch::profile(object $target) |
ProfilingProxy |
Create a profiling proxy for automatic method timing |
Stopwatch::getProfile(ProfilingProxy $proxy) |
array<string, StopwatchStats> |
Get profiling data from a proxy |
RunningStopwatch->onThreshold(float $ms, callable) |
self |
Register threshold callback fired on stop() |
RunningStopwatch->lap(?string $name) |
self |
Record a lap with an optional name |
RunningStopwatch->child(string $name) |
RunningStopwatch |
Create a nested child stopwatch |
RunningStopwatch->stop() |
StopwatchResult |
Stop the timer and return results |
RunningStopwatch->pause() |
void |
Pause timing without stopping the stopwatch |
RunningStopwatch->resume() |
void |
Resume timing after a pause |
RunningStopwatch->getElapsedSoFar() |
float |
Get elapsed seconds without stopping |
RunningStopwatch->elapsed() |
float |
Get elapsed milliseconds while still running |
RunningStopwatch->isRunning() |
bool |
Check if the stopwatch is still active |
RunningStopwatch->isPaused() |
bool |
Check if the stopwatch is currently paused |
StopwatchResult->report() |
string |
Generate a formatted report with all laps |
StopwatchResult->children() |
array<StopwatchResult> |
Get child stopwatch results |
StopwatchResult->stats() |
StopwatchStats |
Get statistical analysis of lap durations |
Value Objects
StopwatchResult — duration (float, ms), durationFormatted (string), memory (int, bytes), memoryFormatted (string), peakMemory (int, bytes), laps (array), name (?string), children (array)
MeasureResult — duration (float, ms), durationFormatted (string), memory (int, bytes), memoryFormatted (string)
Lap — name (?string), duration (float, ms), cumulativeDuration (float, ms)
BenchmarkResult — results() (array of BenchmarkEntry), report() (string)
BenchmarkEntry — mean (float, ms), median (float, ms), min (float, ms), max (float, ms), iterations (int)
StopwatchStats — mean(), median(), min(), max(), p95(), p99(), standardDeviation() (all float, ms)
ComparisonReport — toTable() (string), fastest() (BenchmarkEntry), slowest() (BenchmarkEntry), rankings() (array), toArray() (array)
ThresholdMonitor — addThreshold(float $ms, callable) (self), check(StopwatchResult|MeasureResult) (void)
ProfilingProxy — getProfile() (array of StopwatchStats), getTarget() (object), getRawProfile() (array)
Development
Support
If you find this project useful:
License
MIT