PHPackages                             philiprehberger/php-stopwatch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. philiprehberger/php-stopwatch

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

philiprehberger/php-stopwatch
=============================

Precise code execution timer with lap tracking and memory measurement

v1.0.4(today)11MITPHPPHP ^8.2CI passing

Since Mar 15Pushed todayCompare

[ Source](https://github.com/philiprehberger/php-stopwatch)[ Packagist](https://packagist.org/packages/philiprehberger/php-stopwatch)[ Docs](https://github.com/philiprehberger/php-stopwatch)[ RSS](/packages/philiprehberger-php-stopwatch/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (6)Used By (0)

PHP Stopwatch
=============

[](#php-stopwatch)

[![Tests](https://github.com/philiprehberger/php-stopwatch/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-stopwatch/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/f93b76b601f4278433b361793a1c51c40587763a5725e80b253ef5dc329c14c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d73746f7077617463682e737667)](https://packagist.org/packages/philiprehberger/php-stopwatch)[![License](https://camo.githubusercontent.com/676187e3969a4eeedf1f14aa3e3bbbbc2690bcc2782fec5b140e18724393d476/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d73746f707761746368)](LICENSE)

Precise code execution timer with lap tracking and memory measurement.

---

Requirements
------------

[](#requirements)

DependencyVersionPHP^8.2No external dependencies required.

---

Installation
------------

[](#installation)

```
composer require philiprehberger/php-stopwatch
```

---

Usage
-----

[](#usage)

### Quick measurement

[](#quick-measurement)

```
use PhilipRehberger\Stopwatch\Stopwatch;

$result = Stopwatch::measure(function () {
    // Code to measure
    file_get_contents('https://example.com');
});

echo $result->durationFormatted; // "123.45ms"
echo $result->memoryFormatted;   // "1.50KB"
```

### Measurement with return value

[](#measurement-with-return-value)

```
$outcome = Stopwatch::measureWithResult(function () {
    return User::query()->where('active', true)->get();
});

$users = $outcome['result'];
echo $outcome['measure']->durationFormatted; // "45.12ms"
```

### Manual start/stop with laps

[](#manual-startstop-with-laps)

```
$sw = Stopwatch::start('data-pipeline');

// Phase 1
$data = loadData();
$sw->lap('load');

// Phase 2
$transformed = transform($data);
$sw->lap('transform');

// Phase 3
save($transformed);
$sw->lap('save');

$result = $sw->stop();

echo $result->report();
// Stopwatch [data-pipeline]
// -------------------------
// Duration: 1.23s
// Memory:   3.25MB
// Peak:     5.10MB
//
// Laps:
//   load — 200.00ms (cumulative: 200.00ms)
//   transform — 800.00ms (cumulative: 1000.00ms)
//   save — 230.00ms (cumulative: 1230.00ms)
```

### Check elapsed time while running

[](#check-elapsed-time-while-running)

```
$sw = Stopwatch::start();

doSomeWork();

if ($sw->elapsed() > 5000) {
    // Already over 5 seconds, skip remaining work
}

$result = $sw->stop();
```

---

API
---

[](#api)

MethodReturnsDescription`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`RunningStopwatch->lap(?string $name)``self`Record a lap with an optional name`RunningStopwatch->stop()``StopwatchResult`Stop the timer and return results`RunningStopwatch->elapsed()``float`Get elapsed milliseconds while still running`RunningStopwatch->isRunning()``bool`Check if the stopwatch is still active`StopwatchResult->report()``string`Generate a formatted report with all laps### Value Objects

[](#value-objects)

**StopwatchResult** — `duration` (float, ms), `durationFormatted` (string), `memory` (int, bytes), `memoryFormatted` (string), `peakMemory` (int, bytes), `laps` (array), `name` (?string)

**MeasureResult** — `duration` (float, ms), `durationFormatted` (string), `memory` (int, bytes), `memoryFormatted` (string)

**Lap** — `name` (?string), `duration` (float, ms), `cumulativeDuration` (float, ms)

---

Development
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance100

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

[![philiprehberger](https://avatars.githubusercontent.com/u/8218077?v=4)](https://github.com/philiprehberger "philiprehberger (5 commits)")

---

Tags

performanceprofilingtimerbenchmarkstopwatch

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/philiprehberger-php-stopwatch/health.svg)

```
[![Health](https://phpackages.com/badges/philiprehberger-php-stopwatch/health.svg)](https://phpackages.com/packages/philiprehberger-php-stopwatch)
```

###  Alternatives

[ayesh/php-timer

High-resolution and monotonic stop-watch for all your needs. Supports timer start, pause, resume, stop, read, and minimal conversion.

25223.3k10](/packages/ayesh-php-timer)[jsanc623/phpbenchtime

A lightweight benchmark timer and lap profiler for PHP.

2538.9k1](/packages/jsanc623-phpbenchtime)[wikimedia/arc-lamp

Flame graphs and log processing for PHP stack traces.

444.4k](/packages/wikimedia-arc-lamp)[sandstorm/plumber

Profiling Toolkit for Neos Flow and Neos

364.8k](/packages/sandstorm-plumber)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
