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

ActiveLibrary

cspray/precision-stopwatch
==========================

A small library for keeping track of the duration between precise points in time.

0.2.0(3y ago)05.3k1MITPHPPHP ^8.1

Since May 7Pushed 3y ago1 watchersCompare

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

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

Precision Stopwatch
===================

[](#precision-stopwatch)

Precisely time PHP scripts and code, down to the nanosecond, by utilizing the [hrtime](https://php.net/hrtime) function.

Installing
----------

[](#installing)

[Composer](https://getcomposer.org) is the only supported method for installing this library.

```
composer require cspray/precision-stopwatch
```

Usage Guide
-----------

[](#usage-guide)

Using the provided functionality involves the following steps:

1. Create a new instance of `Cspray\PrecisionStopwatch\Stopwatch`
2. Call `Stopwatch::start()`
3. Do the thing that you're timing!
4. Call `Stopwatch::mark()` (optional, see [*Marking Time*](#marking-time))
5. Call `Stopwatch::stop()`
6. Retrieve information about how long the Stopwatch ran with `Cspray\PrecisionStopwatch\Metrics`

The code examples below can be executed by cloning this repo and running the scripts available in `./examples`.

### Basic Usage

[](#basic-usage)

```
