PHPackages                             oscmarb/phpunit-speedgun - 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. oscmarb/phpunit-speedgun

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

oscmarb/phpunit-speedgun
========================

Search for slow tests in your PHPUnit test suite

1.0.0(2y ago)73MITPHPPHP &gt;=8.0

Since Nov 2Pushed 2y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

phpunit-speedgun
================

[](#phpunit-speedgun)

**SpeedGun** detects slow tests executed with PHPUnit and displays them in the console.

The execution times of tests can vary for various reasons, such as system load, disk access, etc. This tool can identify tests that are considered slow but may not provide an explanation for why they are slow.

[![Screenshot of terminal using SpeedGun](https://repository-images.githubusercontent.com/667299256/4c7f0268-7e86-446b-8773-5d2f175fd961)](https://repository-images.githubusercontent.com/667299256/4c7f0268-7e86-446b-8773-5d2f175fd961)

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

[](#installation)

**SpeedGun** is installed using [Composer](http://getcomposer.org). Add it as a `require-dev` dependency:

```
composer require --dev oscmarb/phpunit-speedgun

```

Usage
-----

[](#usage)

Enable with all defaults by adding the following code to your project's `phpunit.xml` file:

```

    ...

```

Now run the test suite. If one or more test executions exceed the slowness threshold (100ms by default), **SpeedGun** will report on those tests in the console after all tests have completed.

Configuring the extension
-------------------------

[](#configuring-the-extension)

**SpeedGun** supports these configuration parameters:

- `slow_threshold` - Number of milliseconds when a test is considered "slow" (Default: 100ms)
- `min_report_length` - Minimum number of slow tests. If the number of slow tests does not exceed the value of `min_report_length`, no results will be displayed. (Default: 0 tests)
- `max_report_length` - Max number of slow tests included in the report. Must be greater than `min_report_length` (Default: all tests)
- `pattern_thresholds` - Regex expression to apply special conditions to a set of tests.

Each parameter is set in `phpunit.xml`:

```

                        100

                        3

                        5

                                500

```

Custom slowness threshold per-test case
---------------------------------------

[](#custom-slowness-threshold-per-test-case)

There are some tests that, due to their implementation, are slower (or faster) than the average of the tests in our suite. For this reason, there are different ways to customize the threshold.

### Annotation

[](#annotation)

The `@slowThreshold` annotation can set a threshold. This value can be higher or lower than the general threshold. The set threshold will only be used for the test in which we are using it.

```
class SlowTestCase extends PHPUnit\Framework\TestCase
{
    /**
     * @slowThreshold 5000
     */
    public function testSlow()
    {
        // Code that takes a longer time to execute
    }
}
```

Setting `@slowThreshold 0` will never report that test as slow.

### Regex expression

[](#regex-expression)

Another alternative is to use regular expressions to set a threshold for a set of tests. Tests are identified by `class::method`. For example: `App\SlowTestCase::test_slow`.

Suppose we have integration tests with Doctrine, and we want to increase the threshold for these tests as they are slower than the unit tests. We can go test by test and update the threshold using annotations.

This process is slow, and furthermore, we could end up with tests lacking the correct annotation. If we know that all tests with Doctrine contain the word `Doctrine`, we can configure a different threshold as follows:

```

                                500

```

Disable slowness profiling using an environment variable
--------------------------------------------------------

[](#disable-slowness-profiling-using-an-environment-variable)

**SpeedGun** profiles for slow tests when enabled in phpunit.xml. But using an environment variable named `PHPUNIT_SPEED_GUN`can enable or disable the extension:

```
PHPUNIT_SPEED_GUN="0" ./vendor/bin/phpunit****

```

or

```
PHPUNIT_SPEED_GUN="disabled" ./vendor/bin/phpunit****

```

The value of the environment variable can also be set in the `phpunit.xml` file:

```

```

Setup
-----

[](#setup)

### Requirements

[](#requirements)

- Docker

### Instructions

[](#instructions)

Follow the steps below to set up the environment that allows you to modify and test **SpeedGun**:

```
# Clone the project (or fork it)
$ git clone git@github.com:oscmarb/phpunit-speedgun.git

# Build docker image and install dependencies
$ make

# Run test suite to verify code runs as expected
$ make phpunit

```

Makefile file contains all available commands.

PHP Version Support Policy
--------------------------

[](#php-version-support-policy)

This package supports PHP versions with [active support](https://www.php.net/supported-versions.php).

The maintainers of this package add support for a PHP version following its initial release and drop support for a PHP version when it has reached its end of active support.

License
-------

[](#license)

**phpunit-speedgun** is available under the MIT License.

Credits
-------

[](#credits)

This package is inspired by [`johnkary/phpunit-speedtrap`](https://github.com/johnkary/phpunit-speedtrap), originally licensed under MIT by [John Kary](https://github.com/johnkary)

Social
------

[](#social)

Follow [@oscmarb](https://twitter.com/intent/follow?screen_name=oscmarb) on Twitter.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

926d ago

### Community

Maintainers

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

---

Top Contributors

[![omartinezcli](https://avatars.githubusercontent.com/u/165768809?v=4)](https://github.com/omartinezcli "omartinezcli (8 commits)")

---

Tags

phpunitlistenerprofileslowextensionHOOKspeed

### Embed Badge

![Health badge](/badges/oscmarb-phpunit-speedgun/health.svg)

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

###  Alternatives

[johnkary/phpunit-speedtrap

Find and report on slow tests in your PHPUnit test suite

78137.2M122](/packages/johnkary-phpunit-speedtrap)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[juampi92/test-seo

Easy way to test your SEO

26341.0k](/packages/juampi92-test-seo)[ttn/tea

TYPO3 example extension for unit testing and best practices

9121.5k](/packages/ttn-tea)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)

PHPackages © 2026

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