PHPackages                             christiaanbye/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. christiaanbye/stopwatch

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

christiaanbye/stopwatch
=======================

Drop-dead simple execution time measurements

0.3.0(4y ago)04.0kMITPHPPHP ^5.4 || ^7.0 || ^8.0

Since Jul 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ChristiaanBye/stopwatch)[ Packagist](https://packagist.org/packages/christiaanbye/stopwatch)[ RSS](/packages/christiaanbye-stopwatch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Stopwatch
=========

[](#stopwatch)

As the name implies, this is a helper for profiling code in PHP. The library is designed with the following in mind:

1. **Absolute minimal overhead**. The reason you are reading this, is you likely have one or more short tasks to profile. Polluting the results by adding a few hundreds of a second in overhead, won't do anybody good.
2. **Drop-dead simple API**. No decision-making in how the results should be presented or how to name the measuring instance. Just a simple start and stop with maybe a few laps in between. If you require more advanced features, in-code profiling might not be the most suitable approach for your use case.
3. **Maximum compatibility with older PHP versions**. The most of us have had the joy of working with end-of-life PHP versions. Thankfully versioning exists, so one could install an older version of their library of choice. Unfortunately this sometimes does come at the expense of a subtly altered public API. I'd rather remove mental friction than add to it, so you can use the very same library with age-old PHP 5.6 all the way to modern-day PHP 8.

Prerequisites
-------------

[](#prerequisites)

- PHP 5.4 or later

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

[](#installation)

Installation can be easily done using Composer:

```
composer require christiaanbye/stopwatch
```

Advanced users may advocate to add the `--dev` flag and rely on their quality gate to detect usages of the undefined Stopwatch class to prevent accidental production use.

Usage
-----

[](#usage)

For basic use, you can use the `start()`, `stop()` and `elapsed()` methods:

```
use Stopwatch\Stopwatch;

Stopwatch::start(); // Start the stopwatch

// ... run your tasks here

echo Stopwatch::elapsed(); // Optionally take a peek at the elapsed time

// ... run some more tasks here

Stopwatch::stop(); // Stop the stopwatch once your tasks have ran

echo Stopwatch::elapsed(); // Output the time elapsed between the moment the stopwatch was started and stopped
```

The `elapsed()` method returns a float of one of the following:

- If the stopwatch is still running, the amount of time passed since starting the stopwatch and now
- If the stopwatch has been stopped, the amount of time passed since starting and stopping the stopwatch

The latter can be useful if you wish to log the elapsed time further down execution.

In more advanced use cases, one can also make use of the `split()` method in conjunction with the `getSplits()` method. This allows you to record the intermediate time between tasks:

```
use Stopwatch\Stopwatch;

Stopwatch::start();

// ... run a first batch of tasks here

Stopwatch::split('1st batch of tasks');

// ... run a second batch of tasks here

Stopwatch::split('2nd batch of tasks');

// ... run a third batch of tasks here

Stopwatch::split('3rd batch of tasks');

// ... optionally run more tasks for which an intermediate time is not necessary

Stopwatch::stop();

print_r(Stopwatch::getSplits()); // Output the time elapsed between the moment the stopwatch was started and stopped
```

The `getSplits()` method returns all intermediates and the overall time as an array containing the following:

- The time since the stopwatch was started
- The time between the previous and current intermediate

The result of the above code looks as follows:

```
Array
(
    [1st batch of tasks] => Array
        (
            [sinceStart] => 0.007193305
        )

    [2nd batch of tasks] => Array
        (
            [sinceStart] => 0.012397519
            [sincePreviousSplit] => 0.005204214
        )

    [3rd batch of tasks] => Array
        (
            [sinceStart] => 0.01354921
            [sincePreviousSplit] => 0.001151691
        )

    [overall] => Array
        (
            [sinceStart] => 0.01888658
        )

)

```

Similarly to the `elapsed()` method, the stopwatch can be stopped prior to calling `getSplits()` so the recorded execution times are not affected by logging late during runtime.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

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 ~4 days

Total

4

Last Release

1737d ago

PHP version history (2 changes)0.1.0PHP ^5.6 || ^7.0 || ^8.0

0.2.0PHP ^5.4 || ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6db360f9e2881d726d2850884979551d5495b0722b05e678e720c43c72eb06ff?d=identicon)[Christiaan Bye](/maintainers/Christiaan%20Bye)

---

Top Contributors

[![ChristiaanBye](https://avatars.githubusercontent.com/u/1265576?v=4)](https://github.com/ChristiaanBye "ChristiaanBye (15 commits)")

---

Tags

phpprofilingstopwatchtimerperformancetimetimerbenchmarkstopwatch

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[composer/xdebug-handler

Restarts a process without Xdebug.

2.6k397.5M90](/packages/composer-xdebug-handler)[ayesh/php-timer

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

22226.4k11](/packages/ayesh-php-timer)[rarst/laps

Light WordPress profiler.

567262.1k2](/packages/rarst-laps)[jsanc623/phpbenchtime

A lightweight benchmark timer and lap profiler for PHP.

2539.1k1](/packages/jsanc623-phpbenchtime)[dragon-code/benchmark

Simple comparison of code execution speed between different options

11934.7k5](/packages/dragon-code-benchmark)

PHPackages © 2026

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