PHPackages                             jsanc623/phpbenchtime - 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. jsanc623/phpbenchtime

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

jsanc623/phpbenchtime
=====================

A lightweight benchmark timer and lap profiler for PHP.

v3.0.1(3mo ago)2539.1k↓50%21MITPHPPHP &gt;=8.1CI passing

Since Jul 23Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/nsa-yoda/PHPBenchTime)[ Packagist](https://packagist.org/packages/jsanc623/phpbenchtime)[ RSS](/packages/jsanc623-phpbenchtime/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (11)Used By (1)

PHPBenchTime v3.0.0
===================

[](#phpbenchtime-v300)

[![CI](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/ci.yml/badge.svg)](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/ci.yml)[![Total Downloads](https://camo.githubusercontent.com/85d2cc4fe21221318f150d7af46c0a19eb5ed9e72e91e81ee7d323d4e2d1a9fa/68747470733a2f2f706f7365722e707567782e6f72672f6a73616e633632332f70687062656e636874696d652f646f776e6c6f616473)](https://packagist.org/packages/jsanc623/phpbenchtime)[![Monthly Downloads](https://camo.githubusercontent.com/4359f85b4de326a36e016ef7b4dfb503133c8d56571d0774a7100d4874d96699/68747470733a2f2f706f7365722e707567782e6f72672f6a73616e633632332f70687062656e636874696d652f642f6d6f6e74686c79)](https://packagist.org/packages/jsanc623/phpbenchtime)[![License](https://camo.githubusercontent.com/8b3d900b1fac8ed568dc0e35768bdc5a9c5eead012463cf02544824f1f7063f5/68747470733a2f2f706f7365722e707567782e6f72672f6a73616e633632332f70687062656e636874696d652f6c6963656e7365)](https://packagist.org/packages/jsanc623/phpbenchtime)[![Dependabot Updates](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/dependabot/dependabot-updates)[![pages-build-deployment](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/nsa-yoda/PHPBenchTime/actions/workflows/pages/pages-build-deployment)

A lightweight benchmark timer for PHP with laps, pause/unpause support, and a simple summary output.
Designed for clarity, correctness, and minimal overhead.

> **PHPBenchTime v3.0 requires PHP 8.1+** (enum-backed state, typed properties, private internals).

If you’re interested, there is also a Python implementation:
👉 **PyBenchTime** —

---

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

[](#installation)

Install via Composer:

```
composer require nsa-yoda/phpbenchtime
```

Autoloading is handled automatically.

Quick Start
-----------

[](#quick-start)

```

```

Core Concepts
-------------

[](#core-concepts)

- Timers are stateful and controlled via methods only
- All internal properties are private
- State is represented by a PHP 8.1 enum
- All timings are floats (seconds, from microtime(true))
- summary() returns a read-only snapshot

Public API
----------

[](#public-api)

### Methods

[](#methods)

```
start(string $name = "start"): void
end(): void
reset(): void
lap(?string $name = null): void
summary(): array
pause(): void
unpause(): void
```

### Read-only Getters

[](#read-only-getters)

```
getState(): TimerState
getStartTime(): float
getEndTime(): float
getPauseTime(): float
getTotalPauseTime(): float
getLaps(): array
getLapCount(): int
```

Basic Usage
-----------

[](#basic-usage)

```
$t = new Timer();
$t->start();

sleep(3);

$t->end();

print_r($t->summary());
```

### Example Output

[](#example-output)

```
Array
(
    [running] => -1
    [start]   => 1706812345.1234
    [end]     => 1706812348.1239
    [total]   => 3.0005
    [paused]  => 0
    [laps]    => Array
        (
            [0] => Array
                (
                    [name]  => start
                    [start] => 1706812345.1234
                    [end]   => 1706812348.1239
                    [total] => 3.0005
                )
        )
)
```

running is the enum value: 1 = RUNNING, 0 = PAUSED, -1 = STOPPED

### Laps

[](#laps)

Laps allow you to isolate portions of execution time. Each call to lap() automatically closes the previous lap.

```
$t = new Timer();
$t->start();

sleep(1);
$t->lap();

sleep(2);
$t->lap();

$t->end();
```

### Named Laps

[](#named-laps)

For clearer output, provide names to start() and lap():

```
$t = new Timer();
$t->start('bootstrap');

sleep(1);
$t->lap('database');

sleep(1);
$t->lap('render');

$t->end();
```

### Pause &amp; Unpause

[](#pause--unpause)

Paused time is excluded from total runtime but still tracked.

```
$t = new Timer();
$t->start();

sleep(1);
$t->lap('before pause');

$t->pause();
sleep(3); // excluded from total
$t->unpause();

sleep(1);
$t->lap('after pause');

$t->end();
```

Paused duration is available via:

```
$t->getTotalPauseTime();
```

Calling end() while paused will automatically finalize the pause.

Documentation
-------------

[](#documentation)

A richer usage guide (with examples and explanations) is available in: `docs/index.html`

This file can be found on th rpojrects GitHub Pages:

History
-------

[](#history)

- v3.0.0 - Changes to tighten up the codebase for PHP8.1, strongly typed, and enums etc
- v2.1.0 - Performance improvements, unit tests, PHP 8.1 modernization
- v2.0.0 - Complete rewrite: pause/unpause, centralized lap system, detailed summary
- v1.3.0 - Laps, laps, laps
- v1.2.0 - Non-static namespaces
- v1.1.0 - Static namespaces
- v1.0.0 - Static birth

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance80

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 94.6% 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 ~701 days

Recently: every ~835 days

Total

7

Last Release

106d ago

Major Versions

2.1.3 → v3.0.02026-02-01

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1890716?v=4)[Juan Sanchez](/maintainers/nsa-yoda)[@nsa-yoda](https://github.com/nsa-yoda)

---

Top Contributors

[![nsa-yoda](https://avatars.githubusercontent.com/u/1890716?v=4)](https://github.com/nsa-yoda "nsa-yoda (70 commits)")[![andyfleming](https://avatars.githubusercontent.com/u/721038?v=4)](https://github.com/andyfleming "andyfleming (2 commits)")[![josepgv](https://avatars.githubusercontent.com/u/7456368?v=4)](https://github.com/josepgv "josepgv (1 commits)")[![mjaschen](https://avatars.githubusercontent.com/u/328130?v=4)](https://github.com/mjaschen "mjaschen (1 commits)")

---

Tags

lapphptimerprofilerperformancetimerbenchmarkstopwatchbenchtime

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jsanc623-phpbenchtime/health.svg)

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

###  Alternatives

[phpunit/php-timer

Utility class for timing

7.7k876.7M130](/packages/phpunit-php-timer)[phpbench/phpbench

PHP Benchmarking Framework

2.0k13.0M627](/packages/phpbench-phpbench)[dama/doctrine-test-bundle

Symfony bundle to isolate doctrine database tests and improve test performance

1.2k37.2M144](/packages/dama-doctrine-test-bundle)[phpbenchmark/phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

8011.4k2](/packages/phpbenchmark-phpbenchmark)[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)[friendsofcake/fixturize

CakePHP Fixture classes to help increase productivity or performance

24504.7k1](/packages/friendsofcake-fixturize)

PHPackages © 2026

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