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

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

razra/stopwatch
===============

PHP Stopwatch

1.0.1(8y ago)09MITPHPPHP ^7.1

Since Feb 17Pushed 8y agoCompare

[ Source](https://github.com/razra/stopwatch)[ Packagist](https://packagist.org/packages/razra/stopwatch)[ RSS](/packages/razra-stopwatch/feed)WikiDiscussions master Synced yesterday

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

Stopwatch component
===================

[](#stopwatch-component)

[![Build Status](https://camo.githubusercontent.com/b9c7d138a8caa42ba3a1ddb6c07ac0c153802271a6d14c3ae7851d204c52de3f/68747470733a2f2f7472617669732d63692e6f72672f72617a72612f73746f7077617463682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/razra/stopwatch)[![License](https://camo.githubusercontent.com/38578aa0815f806a6dd12234e04ccff99838c7469b35b2adbf7b55617b92ac6d/68747470733a2f2f706f7365722e707567782e6f72672f72617a72612f73746f7077617463682f6c6963656e7365)](https://packagist.org/packages/razra/stopwatch)

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

[](#installation)

`composer require "razra/stopwatch: ^1"`

How to use
----------

[](#how-to-use)

1. You can define stopwatch in 2 ways

    First:

    ```
    $stopwatch = new Stopwatch('someName');
    ```

    Second:

    ```
    $stopwatch = Stopwatch::start('someName');
    // or without parameter (that stopwatch will try to get name of method where its called)
    $stopwatch = Stopwatch::start();
    ```
2. Stop the stopwatch

    ```
    $stopwatch->stop();
    ```
3. Generate html report

    ```
    // it will create html page with report of stopwatches in given path
    $reporter = new HtmlReported('path/to/your/folder');
    $reporter->report();
    ```

Availability to create custom reporter
--------------------------------------

[](#availability-to-create-custom-reporter)

You can always create you report if you want. You can get all executed stopwatches from `StopwatchCollection::getAll()`, it will return array of `Stopwatch` objects all execute stopwatches.

Example structure:

```
    [
        'sectionName' => [
            new Stopwatch(),
            new Stopwatch(),
            new Stopwatch(),
            ...
        ],
        'anotherSectionName' => [
            new Stopwatch(),
            new Stopwatch(),
            new Stopwatch(),
            ...
        ],
        ...
    ]

```

Usage example:

```
