PHPackages                             8ctopus/nano-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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. 8ctopus/nano-timer

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

8ctopus/nano-timer
==================

Measure time between events, variability and compare results.

4.1.1(5mo ago)12.4k1MITPHPPHP &gt;=8.1CI passing

Since May 29Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/8ctopus/nano-timer)[ Packagist](https://packagist.org/packages/8ctopus/nano-timer)[ Docs](https://github.com/8ctopus/nano-timer)[ RSS](/packages/8ctopus-nano-timer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (30)Used By (1)

nano timer
==========

[](#nano-timer)

[![packagist](https://camo.githubusercontent.com/1c687fb33ed7e24413fa6b91abc4742f18bae50f77a423afa0dc6c98550194fa/68747470733a2f2f706f7365722e707567782e6f72672f3863746f7075732f6e616e6f2d74696d65722f76)](https://packagist.org/packages/8ctopus/nano-timer)[![downloads](https://camo.githubusercontent.com/ca93dc57d897cd2f40e4dfcfdb9b16602186a88360ba3df6d5c018de0c5ffce9/68747470733a2f2f706f7365722e707567782e6f72672f3863746f7075732f6e616e6f2d74696d65722f646f776e6c6f616473)](https://packagist.org/packages/8ctopus/nano-timer)[![min php version](https://camo.githubusercontent.com/d92bf1e397402a479c8c55a57203c6d7c0fd0ea78d4ba43aa51b97fd0df7274e/68747470733a2f2f706f7365722e707567782e6f72672f3863746f7075732f6e616e6f2d74696d65722f726571756972652f706870)](https://packagist.org/packages/8ctopus/nano-timer)[![license](https://camo.githubusercontent.com/52e13f905070b863ad48aae74a01858205bdaffdd043263d5f141eb29151c86c/68747470733a2f2f706f7365722e707567782e6f72672f3863746f7075732f6e616e6f2d74696d65722f6c6963656e7365)](https://packagist.org/packages/8ctopus/nano-timer)[![tests](https://github.com/8ctopus/nano-timer/actions/workflows/tests.yml/badge.svg)](https://github.com/8ctopus/nano-timer/actions/workflows/tests.yml)[![code coverage badge](https://raw.githubusercontent.com/8ctopus/nano-timer/image-data/coverage.svg)](https://raw.githubusercontent.com/8ctopus/nano-timer/image-data/coverage.svg)[![lines of code](https://raw.githubusercontent.com/8ctopus/nano-timer/image-data/lines.svg)](https://raw.githubusercontent.com/8ctopus/nano-timer/image-data/lines.svg)

Yet another php timer

why another timer?
------------------

[](#why-another-timer)

The main reason I built this timer was to analyze slow requests that occur from time to time on the production server where using tools such as [XDebug](https://github.com/xdebug/xdebug) or [php SPX](https://github.com/NoiseByNorthwest/php-spx) is not advisable.

features
--------

[](#features)

- measure timing between events
- measure variability for the same code loop
- compare results side by side
- log only requests slower than a given threshold
- automatically log when the destructor is called
- measure peak memory use

install
-------

[](#install)

- `composer require 8ctopus/nano-timer`

demo
----

[](#demo)

There's `demo.php` in the project root directory that showcases most examples below.

simple timing measurement
-------------------------

[](#simple-timing-measurement)

```
use Oct8pus\NanoTimer\NanoTimer;

require_once __DIR__ . '/vendor/autoload.php';

$timer = new NanoTimer();

usleep(200000);

$timer->measure('usleep 200ms');

foreach (range(0, 50000) as $i) {
    $a = $i * $i;
}

$timer->measure('range 0-50000');

echo $timer->table();
```

```
usleep 200ms  211ms
range 0-50000  12ms
total         223ms
```

more advanced timing
--------------------

[](#more-advanced-timing)

- log autoload and constructor time
- log peak memory use

```
use Oct8pus\NanoTimer\NanoTimer;

// autoload and constructor time
$hrtime = hrtime(true);

require_once __DIR__ . '/vendor/autoload.php';

$timer = new NanoTimer($hrtime);

$timer
    ->logMemoryPeakUse(true);

$timer->measure('autoload and constructor');

usleep(200000);

$timer->measure('200ms sleep');

sleep(1);

$timer->measure('1s sleep');

foreach (range(0, 50000) as $i) {
    $a = $i * $i;
}

$timer->measure('pow range 0-50000');

echo $timer->table();
```

```
autoload and constructor   23ms
200ms sleep               211ms
1s sleep                 1012ms
pow range 0-50000          13ms
total                    1259ms
memory peak use             4MB
```

only log measurements slower than
---------------------------------

[](#only-log-measurements-slower-than)

It's sometimes useful to only log measurements slower than a given threshold. In this example, the request will automatically be logged to the error log when the destructor is called if the total time spent is more than 100 milliseconds.

```
$timer = new NanoTimer();

$timer
    ->logSlowerThan(100)
    ->autoLog();

...
```

```
nanotimer - total: 614ms - destruct: 614ms
```

measure variability
-------------------

[](#measure-variability)

Sometimes you need to understand the speed variability of the same code loop.

```
$variability1 = new NanoVariability();

for ($i = 1; $i < 6; ++$i) {
    $ms = (1000 + rand(0, +200)) * 10;
    usleep($ms);
    $variability1->measure("lap {$i}");
}

echo $variability1->table(true) . "\n";
```

```
lap 1   13ms
lap 2   16ms
lap 3   16ms
lap 4   16ms
lap 5   15ms
average 15ms
median  16ms
minimum 13ms
maximum 16ms
```

compare
-------

[](#compare)

Results can be compared both for timings and variability.

```
$v1 = new NanoVariability();

for ($i = 1; $i < 6; ++$i) {
    usleep(500 + rand(0, 100));
    $v1->measure("lap {$i}");
}

$v2 = new NanoVariability();

for ($i = 1; $i < 6; ++$i) {
    usleep(500 + rand(0, 100));
    $v2->measure("lap {$i}");
}

$compare = new Compare($v1, $v2);
```

```
compare
lap 1     7 13 +86%
lap 2    15 15 +0%
lap 3    15 15 +0%
lap 4    15 15 +0%
lap 5    15 16 +7%
average  13 15 +15%
median   15 15 +0%
minimum   7 13 +86%
maximum  15 16 +7%
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance70

Regular maintenance activity

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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

Every ~32 days

Recently: every ~121 days

Total

29

Last Release

170d ago

Major Versions

1.3.0 → 2.0.02024-01-15

2.3.3 → 3.0.02024-05-14

3.1.1 → 4.0.02024-08-01

PHP version history (2 changes)1.0.0PHP &gt;=7.4

2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4dafd5f7ef8134a5c9b231686c5da3d6416db09139b45aac0b26952178dffb8a?d=identicon)[8ctopus](/maintainers/8ctopus)

---

Top Contributors

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

---

Tags

performancephptimerprofilercomparetimerspeedvariability

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/8ctopus-nano-timer/health.svg)

```
[![Health](https://phpackages.com/badges/8ctopus-nano-timer/health.svg)](https://phpackages.com/packages/8ctopus-nano-timer)
```

###  Alternatives

[barryvdh/laravel-debugbar

PHP Debugbar integration for Laravel

19.1k124.3M624](/packages/barryvdh-laravel-debugbar)[php-debugbar/php-debugbar

Debug bar in the browser for php application

4.4k21.3M40](/packages/php-debugbar-php-debugbar)[fruitcake/laravel-debugbar

PHP Debugbar integration for Laravel

19.1k662.9k29](/packages/fruitcake-laravel-debugbar)[tracy/tracy

😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.

1.8k24.4M1.3k](/packages/tracy-tracy)[fruitcake/laravel-telescope-toolbar

Toolbar for Laravel Telescope based on Symfony Web Profiler

8041.6M3](/packages/fruitcake-laravel-telescope-toolbar)[recca0120/laravel-tracy

A Laravel Package to integrate Nette Tracy Debugger

388283.0k3](/packages/recca0120-laravel-tracy)

PHPackages © 2026

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