PHPackages                             sanovskiy/stopwatch - 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. sanovskiy/stopwatch

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

sanovskiy/stopwatch
===================

Simple, zero-dependency stopwatch for performance profiling

1.1.0(5mo ago)11MITPHPPHP ^8.0

Since Nov 16Pushed 5mo agoCompare

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

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

Stopwatch
=========

[](#stopwatch)

Simple, zero-dependency stopwatch for performance profiling in PHP. **Measures both time and memory consumption.**

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

[](#installation)

```
composer require sanovskiy/stopwatch
```

Usage
-----

[](#usage)

### 1. Basic Timing and Memory Profiling

[](#1-basic-timing-and-memory-profiling)

To enable memory profiling, pass `true` to the constructor.

```
use Sanovskiy\Stopwatch\Stopwatch;

// Enable memory profiling
$stopwatch = new Stopwatch(true);

$stopwatch->start();

// Step 1
usleep(10000);
$stopwatch->checkpoint('database_query');

// Simulate memory intensive work
$data = array_fill(0, 10000, str_repeat('A', 100));
$stopwatch->checkpoint('data_processing');
unset($data); // Memory freed

// Step 3 (recurrent)
for ($i = 0; $i < 5; $i++) {
    usleep(100);
    $stopwatch->checkpoint('loop_iteration');
}

$stopwatch->finish();

// Automatic, adaptive output (CLI or HTML)
echo $stopwatch;
```

### 2. Output Examples (using `echo $stopwatch;`)

[](#2-output-examples-using-echo-stopwatch)

#### CLI Output (When SAPI is `cli`)

[](#cli-output-when-sapi-is-cli)

```
--- CHECKPOINT DATA ---
-----------------------------------------------------------------------------------------------------------------------------------
| Event Name           | Duration (ms)       | Elapsed Time (ms)   | Time %             | Memory Diff          | Memory Peak      |
-----------------------------------------------------------------------------------------------------------------------------------
| start                |              0.0 ms |              0.0 ms |               0.0% | +0 B                 | 2.50 MB          |
| database_query       |             10.0 ms |             10.0 ms |               0.8% | +0 B                 | 2.51 MB          |
| data_processing      |              1.5 ms |             11.5 ms |               0.1% | +1.00 MB             | 3.52 MB          |
| loop_iteration       |              0.1 ms |             11.6 ms |               0.0% | +0 B                 | 3.52 MB          |
| loop_iteration       |              0.1 ms |             11.7 ms |               0.0% | +0 B                 | 3.52 MB          |
| ...                  | ...                 | ...                 | ...                | ...                  | ...              |
| end                  |             10.1 ms |             22.0 ms |               9.3% | -1.00 MB             | 3.52 MB          |
-----------------------------------------------------------------------------------------------------------------------------------

--- AVERAGE DATA ---
------------------------------------------------------------------------------------------
| Name                 | Count              | Avg Duration (ms)   | Avg Memory Diff      |
------------------------------------------------------------------------------------------
| loop_iteration       | 5                  |              0.1 ms | +0 B                 |
------------------------------------------------------------------------------------------

```

#### Web Output (When SAPI is not `cli`)

[](#web-output-when-sapi-is-not-cli)

A styled HTML table will be rendered, including all checkpoints and a separate "Average Checkpoint Data" table.

Features
--------

[](#features)

- Zero dependencies
- Millisecond precision
- Memory profiling (usage and peak)
- Custom checkpoint IDs
- Adaptive, formatted output (`__toString` for CLI and HTML)
- Average time and memory difference calculations for recurrent operations
- Exception handling (e.g., calling `start()` twice)

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance74

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Every ~3 days

Total

2

Last Release

170d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a5521376dceab8922e3b4333bbc17e749e3d39a5b0d63b1afa2a84f5c07331b?d=identicon)[sanovskiy](/maintainers/sanovskiy)

---

Top Contributors

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

---

Tags

performanceprofilingMetricstiming

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sanovskiy-stopwatch/health.svg)

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

###  Alternatives

[composer/xdebug-handler

Restarts a process without Xdebug.

2.6k397.5M90](/packages/composer-xdebug-handler)[rarst/laps

Light WordPress profiler.

567262.1k2](/packages/rarst-laps)[laracraft-tech/laravel-xhprof

Easy XHProf setup to profile your laravel application!

235321.4k](/packages/laracraft-tech-laravel-xhprof)[wikimedia/arc-lamp

Flame graphs and log processing for PHP stack traces.

434.4k](/packages/wikimedia-arc-lamp)[upscale/swoole-blackfire

Blackfire profiler integration for Swoole web-server

22114.0k8](/packages/upscale-swoole-blackfire)[koriym/xdebug-mcp

Universal PHP Xdebug MCP Server with AI-optimized debugging support

4011.6k1](/packages/koriym-xdebug-mcp)

PHPackages © 2026

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