PHPackages                             mts7/php-execution-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mts7/php-execution-timer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mts7/php-execution-timer
========================

Testable PHP timer

1.2.3(2y ago)01931MITPHPPHP ^8.1CI passing

Since Nov 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mts7/php-execution-timer)[ Packagist](https://packagist.org/packages/mts7/php-execution-timer)[ RSS](/packages/mts7-php-execution-timer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (9)Used By (1)

PHP Execution Timer
===================

[](#php-execution-timer)

PHP timer for tracking and accumulating timings

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

[](#installation)

```
composer require mts7/php-execution-timer
```

Usage
-----

[](#usage)

### Single measurement

[](#single-measurement)

When measuring the time for a single event, use `getDuration` to find the amount of time spent on that specific functionality.

```
$timer = new \MtsTimer\Timer();
$timer->start();
doSomething();
$timer->stop();
echo 'Duration: ' . $timer->getDuration() . PHP_EOL;
```

### Multiple measurements

[](#multiple-measurements)

When measuring the time for multiple events, use `getTotalDuration` to find the total durations of all the included functionalities.

```
$timer = new \MtsTimer\Timer();
for ($i = 0; $i < 5; $i++) {
    $timer->start();
    doSomething();
    $timer->stop();
    echo 'Something took ' . $timer->getDuration() . ' seconds.' . PHP_EOL;
}
echo 'Total duration: ' . $timer->getTotalDuration() . PHP_EOL;
```

### Resetting between measurements

[](#resetting-between-measurements)

Some situations require having multiple accumulations that are tracked independently. For these, use `reset` to clear the timers and reset all internal values to `0.0.`.

```
$timer = new \MtsTimer\Timer();
$timings = [];
for ($i = 0; $i < 3; $i++) {
    $timer->reset();
    for ($j = 0; $j < 5; $j++) {
        $timer->start();
        doSomething();
        $timer->stop();
    }
    $timings[] = $timer->getTotalDuration();
}
```

Testing with FixedTimer
-----------------------

[](#testing-with-fixedtimer)

The usual timer in the code is `Timer` while the tests would use `FixedTimer`without changing the code. Having `TimerInterface` is a benefit of using composition. Since both `Timer` and `FixedTimer` have similar functionality, the base functionalities are contained in `AbstractTimer` with overriding methods as necessary.

`FixedTimer` uses two constant (fixed) values (instead of the time): One for start, and another for stop.

### Examples

[](#examples)

These are very simple examples of having a class that uses the timer as well as a class that uses the class and a class that tests the class. In real-world scenarios, use a [container](https://github.com/mts7/php-dependency-injection)for dependency injection and a callable that takes time.

```
class Benchmark
{
    public function __construct(private \MtsTimer\TimerInterface $timer)
    {
    }

    public function run(callable $callable): float
    {
        $this->timer->start();
        $callable();
        $this->timer->stop();

        return $this->timer->getDuration();
    }
}

class RunTheBenchmark
{
    public function execute(): float
    {
        $timer = new \MtsTimer\Timer();
        $benchmark = new Benchmark($timer);
        return $benchmark->run([self::class, 'doNothing']);
    }

    public static function doNothing(): void
    {
    }
}

class BenchmarkTest
{
    public function testRun(): void
    {
        $timer = new \MtsTimer\FixedTimer();
        $benchmark = new Benchmark($timer);

        $duration = $benchmark->run([RunTheBenchmark::class, 'doNothing']);

        $this->assertSame($timer::DURATION, $duration);
    }
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 71.4% 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 ~66 days

Recently: every ~116 days

Total

8

Last Release

823d ago

### Community

Maintainers

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

---

Top Contributors

[![mts7](https://avatars.githubusercontent.com/u/292491?v=4)](https://github.com/mts7 "mts7 (35 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[rabrennie/jupyter-php-kernel

PHP Kernel for Jupyter Notebooks

321.1k](/packages/rabrennie-jupyter-php-kernel)

PHPackages © 2026

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