PHPackages                             teqneers/phpunit-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. [Testing &amp; Quality](/categories/testing)
4. /
5. teqneers/phpunit-stopwatch

ActiveLibrary[Testing &amp; Quality](/categories/testing)

teqneers/phpunit-stopwatch
==========================

Extension to measure and analyse any part of your code in order to detect performance issues using phpunit/phpunit.

0.1.0(2y ago)2978[1 PRs](https://github.com/teqneers/phpunit-stopwatch/pulls)MITPHPPHP &gt;=8.1.0

Since Mar 19Pushed 1y ago2 watchersCompare

[ Source](https://github.com/teqneers/phpunit-stopwatch)[ Packagist](https://packagist.org/packages/teqneers/phpunit-stopwatch)[ Docs](https://github.com/teqneers/phpunit-stopwatch)[ RSS](/packages/teqneers-phpunit-stopwatch/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (3)Used By (0)

phpunit-stopwatch
=================

[](#phpunit-stopwatch)

[![Latest Stable Version](https://camo.githubusercontent.com/74e513674d3226a783b07b926286228c9297a2e39105b3cdfa8724c04e3e594d/68747470733a2f2f706f7365722e707567782e6f72672f7465716e656572732f706870756e69742d73746f7077617463682f76)](https://packagist.org/packages/teqneers/phpunit-stopwatch)[![CI](https://github.com/teqneers/phpunit-stopwatch/actions/workflows/ci.yml/badge.svg)](https://github.com/teqneers/phpunit-stopwatch/actions)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/c1a915a047979a2eba362957a5f6d28b85fd0569e7e88888aec5db5c46364039/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7465716e656572732f706870756e69742d73746f7077617463682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/teqneers/phpunit-stopwatch/?branch=main)[![Code Coverage](https://camo.githubusercontent.com/f43e8a1f76278c58fd1921f850cd45886c147787b978cb59702ac046efb10c17/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7465716e656572732f706870756e69742d73746f7077617463682f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/teqneers/phpunit-stopwatch/?branch=main)[![Code Climate](https://camo.githubusercontent.com/ddec0e9576ece57430e59228ec2c80f96a705dd78b55b07e9152118840676a58/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f7465716e656572732f706870756e69742d73746f7077617463682f6261646765732f6770612e737667)](https://codeclimate.com/github/teqneers/phpunit-stopwatch)[![codecov](https://camo.githubusercontent.com/357b80000fbb96ac64ba38050dd5cd163c76e659e27136e31e915ff1469cec93/68747470733a2f2f636f6465636f762e696f2f67682f7465716e656572732f706870756e69742d73746f7077617463682f67726170682f62616467652e7376673f746f6b656e3d553154375a4757355857)](https://codecov.io/gh/teqneers/phpunit-stopwatch)[![Type Coverage](https://camo.githubusercontent.com/fafd5977c7c2c050e145c8b20fef31b8398de92e058f8f1c8524c549a3a6df59/68747470733a2f2f73686570686572642e6465762f6769746875622f7465716e656572732f706870756e69742d73746f7077617463682f636f7665726167652e737667)](https://shepherd.dev/github/teqneers/phpunit-stopwatch)

Project information: [![License](https://camo.githubusercontent.com/cea7de57bd2a01d85d8f76e7762d850a8d760a600e3c4a0cdf6a3eb169c443c4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7465716e656572732f706870756e69742d73746f7077617463682e7376673f7374796c653d666c6174)](https://img.shields.io/github/license/teqneers/phpunit-stopwatch.svg?style=flat)[![GitHub code size in bytes](https://camo.githubusercontent.com/539ecc60eddb5511e33712a806b7b72673a54c56df248650a4c157941c4683b0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f7465716e656572732f706870756e69742d73746f7077617463682e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/539ecc60eddb5511e33712a806b7b72673a54c56df248650a4c157941c4683b0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f7465716e656572732f706870756e69742d73746f7077617463682e7376673f7374796c653d666c6174)

Stopwatch is an essential [`phpunit/phpunit`](https://github.com/sebastianbergmann/phpunit) extension for performance analysis!

Gain invaluable insights into your code's execution time and call frequency during test runs. The extension is designed to elevate your code performance analysis. Track the execution time and frequency of any marked code segments to address performance bottlenecks with precision. You can identify performance bottlenecks (e.g., database cleanups or setup) or just monitor them over time. The extension will generate stopwatch reports for each test as well as a summary report at the end of the test run.

This project provides a [`composer`](https://getcomposer.org) package and a [Phar archive](https://www.php.net/manual/en/book.phar.php).

The extension is compatible with the following versions of `phpunit/phpunit`:

- [`phpunit/phpunit:^10.1.0`](https://github.com/sebastianbergmann/phpunit/tree/10.1.0)
- [`phpunit/phpunit:^11.0.0`](https://github.com/sebastianbergmann/phpunit/tree/11.0.0)

Once you've added some measurement points to your code, the extension will stop watch and count them. The results are displayed for each test and as a total report at the end of the test run.

Here is an example of how the output of a single test class might look:

```
Stopwatch for TQ\Tests\Example\SingleTest::testDataCalculation:
- TQ\Testing\Database::deleteData      0.117secs (    3x, Ø   0.04) TOTAL    327.026secs (  184x, Ø   1.78)
- ...onment\Testing::cleanupInstance   0.259secs (    1x, Ø   0.26) TOTAL      6.159secs (   60x, Ø   0.10)
- TQ\Testing\Database::import          7.889secs (   11x, Ø   0.72) TOTAL    250.958secs (  352x, Ø   0.71)
- Test                                 1.428secs (    1x, Ø   1.43) TOTAL   1041.228secs (   70x, Ø  14.87)
.

Stopwatch for TQ\Tests\Example\SingleTest::testDataTransfer:
- TQ\Testing\Database::deleteData      0.116secs (    3x, Ø   0.04) TOTAL    327.142secs (  187x, Ø   1.75)
- ...onment\Testing::cleanupInstance   0.256secs (    1x, Ø   0.26) TOTAL      6.415secs (   61x, Ø   0.11)
- TQ\Testing\Database::import          7.573secs (   11x, Ø   0.69) TOTAL    258.531secs (  363x, Ø   0.71)
- Test                                 5.998secs (    1x, Ø   6.00) TOTAL   1047.226secs (   71x, Ø  14.75)
.

Stopwatch for TQ\Tests\Example\SingleTest TearDown:
- TQ\Testing\Database::deleteData     38.486secs (    6x, Ø   6.41) TOTAL    365.511secs (  190x, Ø   1.92)
- ...onment\Testing::cleanupInstance   0.256secs (    1x, Ø   0.26) TOTAL      6.415secs (   61x, Ø   0.11)
- TQ\Testing\Database::import          7.573secs (   11x, Ø   0.69) TOTAL    258.531secs (  363x, Ø   0.71)
- Test                                 5.998secs (    1x, Ø   6.00) TOTAL   1047.226secs (   71x, Ø  14.75)
```

And at the end of the test run, you will get a summary of all stopwatches used, and it is going to look like this:

```
Stopwatch TOTALS:
- Test                                     TOTAL   1047.246secs (   78x, Ø  13.43)
- TQ\Testing\Database::deleteData          TOTAL    365.511secs (  190x, Ø   1.92)
- TQ\Testing\Database::import              TOTAL    258.531secs (  363x, Ø   0.71)
- ...onment\Testing::cleanupInstance       TOTAL      6.416secs (   62x, Ø   0.10)
- TQ\Production\Monitoring::ping           TOTAL     17.967secs (    7x, Ø   2.57)
```

### Usage

[](#usage)

Stopwatch is very easy to use. A single line of code wrapped around the code you want to measure is all it takes.

For instance, let's say your tests are pretty slow, but you don't know who's the culprit? You suspect that it might be the database setup that has to be done for each and every test. Simply wrap the suspected code block as follows:

```
        Stopwatch::start(__METHOD__);

        self::initializeDatabase(
            $db->getConnection(),
            ...static::createData()
        );

        Stopwatch::stop(__METHOD__);
```

Should the test, setup, teardown, or other relevant methods execute this code, Stopwatch will seamlessly measure its execution time and count, and will present the results within the test output.

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

[](#installation)

### Installation with `composer`

[](#installation-with-composer)

Run

```
composer require --dev teqneers/phpunit-stopwatch
```

to install `teqneers/phpunit-stopwatch` as a `composer` package.

### Installation as Phar

[](#installation-as-phar)

Download `phpunit-stopwatch.phar` from the [latest release](https://github.com/teqneers/phpunit-stopwatch/releases/latest).

Usage
-----

[](#usage-1)

### Bootstrapping the extension

[](#bootstrapping-the-extension)

Before the extension can detect slow tests in `phpunit/phpunit`, you need to bootstrap it. The bootstrapping mechanism depends on the version of `phpunit/phpunit` you are using.

### Bootstrapping the extension as a `composer` package

[](#bootstrapping-the-extension-as-a-composer-package)

To bootstrap the extension as a `composer` package when using

- `phpunit/phpunit:^10.0.0`
- `phpunit/phpunit:^11.0.0`

adjust your `phpunit.xml` configuration file and configure the

- [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element)on [`phpunit/phpunit:^10.1.0`](https://docs.phpunit.de/en/10.5/)
- [`extensions` element](https://docs.phpunit.de/en/11.0/configuration.html#the-extensions-element)on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)

```

+
+
+

             test/Unit/

```

### Bootstrapping the extension as a PHAR

[](#bootstrapping-the-extension-as-a-phar)

To bootstrap the extension as a PHAR when using

- `phpunit/phpunit:^10.1.0`
- `phpunit/phpunit:^11.0.0`

adjust your `phpunit.xml` configuration file and configure the

- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/10.5/configuration.html#the-extensionsdirectory-attribute)and the [`extensions` element](https://docs.phpunit.de/en/10.5/configuration.html#the-extensions-element)on [`phpunit/phpunit:^10.0.0`](https://docs.phpunit.de/en/10.5/)
- [`extensionsDirectory` attribute](https://docs.phpunit.de/en/11.0/configuration.html#the-extensionsdirectory-attribute)and the [`extensions` element](https://docs.phpunit.de/en/11.0/configuration.html#the-extensions-element)on [`phpunit/phpunit:^11.0.0`](https://docs.phpunit.de/en/11.0/)

```

+
+
+

             test/Unit/

```

### Configuring the extension

[](#configuring-the-extension)

So far, there are no configuration settings for this extension.

### Running tests

[](#running-tests)

When you have bootstrapped the extension, you can run your tests as usually. E.g.:

```
vendor/bin/phpunit
```

When the extension is used somewhere in your code, it will give you a report:

License
-------

[](#license)

This project uses the [MIT license](LICENSE.md).

Credits
-------

[](#credits)

This package is inspired by [`ergebnis/phpunit-slow-test-detector`](https://github.com/ergebnis/phpunit-slow-test-detector/).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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

Unknown

Total

1

Last Release

782d ago

### Community

Maintainers

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

---

Top Contributors

[![ogmueller](https://avatars.githubusercontent.com/u/788989?v=4)](https://github.com/ogmueller "ogmueller (73 commits)")

---

Tags

bottleneckextensionmeasureperformancephpunitslowstopwatchtesttimephpunittestperformancetimeslowextensionstopwatchmeasure

###  Code Quality

Static AnalysisPsalm, Rector

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[mdarse/phpunit-notifier

Desktop notifications for PHPUnit

322.2k3](/packages/mdarse-phpunit-notifier)

PHPackages © 2026

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