PHPackages                             phpunit/php-timer - 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. phpunit/php-timer

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

phpunit/php-timer
=================

Utility class for timing

9.0.0(3mo ago)7.7k876.7M↓13.3%63[1 issues](https://github.com/sebastianbergmann/php-timer/issues)[2 PRs](https://github.com/sebastianbergmann/php-timer/pulls)20BSD-3-ClausePHPPHP &gt;=8.4CI passing

Since Sep 23Pushed today19 watchersCompare

[ Source](https://github.com/sebastianbergmann/php-timer)[ Packagist](https://packagist.org/packages/phpunit/php-timer)[ Docs](https://github.com/sebastianbergmann/php-timer/)[ GitHub Sponsors](https://github.com/sebastianbergmann)[ Fund](https://liberapay.com/sebastianbergmann)[ RSS](/packages/phpunit-php-timer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (35)Used By (20)

phpunit/php-timer
=================

[](#phpunitphp-timer)

[![Latest Stable Version](https://camo.githubusercontent.com/f9bfb048f51c585ccc54513a75b580b45de7cbf9a04daff3ef1cc44b1ee3ff02/68747470733a2f2f706f7365722e707567782e6f72672f706870756e69742f7068702d74696d65722f76)](https://packagist.org/packages/phpunit/php-timer)[![CI Status](https://github.com/sebastianbergmann/php-timer/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/php-timer/actions)[![codecov](https://camo.githubusercontent.com/6d30ad51045905b63c775853a8ff5bf6c3fe4b7dd0853edafeeeac839a9e59a8/68747470733a2f2f636f6465636f762e696f2f67682f73656261737469616e626572676d616e6e2f7068702d74696d65722f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/sebastianbergmann/php-timer)

Utility class for timing things, factored out of PHPUnit into a stand-alone component.

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

[](#installation)

You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):

```
composer require phpunit/php-timer

```

If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:

```
composer require --dev phpunit/php-timer

```

Usage
-----

[](#usage)

### Basic Timing

[](#basic-timing)

```
require __DIR__ . '/vendor/autoload.php';

use SebastianBergmann\Timer\Timer;

$timer = new Timer;

$timer->start();

foreach (\range(0, 100000) as $i) {
    // ...
}

$duration = $timer->stop();

var_dump(get_class($duration));
var_dump($duration->asString());
var_dump($duration->asSeconds());
var_dump($duration->asMilliseconds());
var_dump($duration->asMicroseconds());
var_dump($duration->asNanoseconds());
```

The code above yields the output below:

```
string(32) "SebastianBergmann\Timer\Duration"
string(9) "00:00.002"
float(0.002851062)
float(2.851062)
float(2851.062)
int(2851062)

```

### Resource Consumption

[](#resource-consumption)

#### Explicit duration

[](#explicit-duration)

```
require __DIR__ . '/vendor/autoload.php';

use SebastianBergmann\Timer\ResourceUsageFormatter;
use SebastianBergmann\Timer\Timer;

$timer = new Timer;
$timer->start();

foreach (\range(0, 100000) as $i) {
    // ...
}

print (new ResourceUsageFormatter)->resourceUsage($timer->stop());
```

The code above yields the output below:

```
Time: 00:00.002, Memory: 6.00 MB

```

#### Duration since PHP Startup (using unreliable `$_SERVER['REQUEST_TIME_FLOAT']`)

[](#duration-since-php-startup-using-unreliable-_serverrequest_time_float)

```
require __DIR__ . '/vendor/autoload.php';

use SebastianBergmann\Timer\ResourceUsageFormatter;

foreach (\range(0, 100000) as $i) {
    // ...
}

print (new ResourceUsageFormatter)->resourceUsageSinceStartOfRequest();
```

The code above yields the output below:

```
Time: 00:00.002, Memory: 6.00 MB

```

###  Health Score

83

↑

ExcellentBetter than 100% of packages

Maintenance92

Actively maintained with recent releases

Popularity85

Widely adopted with strong download metrics

Community44

Growing community involvement

Maturity92

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.2% 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 ~148 days

Recently: every ~91 days

Total

34

Last Release

102d ago

Major Versions

2.1.4 → 7.0.12024-07-03

7.0.1 → 8.0.02025-02-07

6.0.x-dev → 7.0.x-dev2025-11-25

7.0.x-dev → 8.0.x-dev2025-12-31

8.0.x-dev → 9.0.02026-02-06

PHP version history (12 changes)1.0.3PHP &gt;=5.2.7

1.0.4PHP &gt;=5.3.3

1.0.9PHP ^5.3.3 || ^7.0

2.0.0PHP ^7.1

3.0.0PHP ^7.3

5.0.1PHP ^7.3 || ^8.0

5.0.2PHP &gt;=7.3

2.1.3PHP &gt;=7.1

6.0.0PHP &gt;=8.1

7.0.0PHP &gt;=8.2

8.0.0PHP &gt;=8.3

9.0.0PHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1089?v=4)[Sebastian Probst Eide](/maintainers/sebastian)[@sebastian](https://github.com/sebastian)

---

Top Contributors

[![sebastianbergmann](https://avatars.githubusercontent.com/u/25218?v=4)](https://github.com/sebastianbergmann "sebastianbergmann (458 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (8 commits)")[![whatthejeff](https://avatars.githubusercontent.com/u/306525?v=4)](https://github.com/whatthejeff "whatthejeff (7 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (3 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (2 commits)")[![sun](https://avatars.githubusercontent.com/u/41992?v=4)](https://github.com/sun "sun (2 commits)")[![mbischof](https://avatars.githubusercontent.com/u/1442526?v=4)](https://github.com/mbischof "mbischof (1 commits)")[![Ayesh](https://avatars.githubusercontent.com/u/811553?v=4)](https://github.com/Ayesh "Ayesh (1 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")[![henriquemoody](https://avatars.githubusercontent.com/u/154023?v=4)](https://github.com/henriquemoody "henriquemoody (1 commits)")[![Majkl578](https://avatars.githubusercontent.com/u/144181?v=4)](https://github.com/Majkl578 "Majkl578 (1 commits)")[![alfredbez](https://avatars.githubusercontent.com/u/1001186?v=4)](https://github.com/alfredbez "alfredbez (1 commits)")

---

Tags

timer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpunit-php-timer/health.svg)

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

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

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