/micro-timer

A simple microtime wrapper to measure PHP scripts execution time.

Primary LanguagePHPMIT LicenseMIT

MicroTimer

A small PHP class to measure PHP scripts execution time.

How to use

Simply initialize a MicroTimer instance to get started.

All methods return the object instance and can be chained.

<?php

    $timer = new MicroTimer();

    $timer->start();

    // do stuff

    echo $timer->stop()->getTime();

?>

Available methods

<?php

    // Start the timer.
    $timer->start();

    // Stop the timer.
    $timer->stop();

    // Get time (milliseconds).
    $timer->getTime();

    // Get time (seconds) with 3 decimals.
    $timer->getTimeInSeconds(3);

    // Erase and reset internal data.
    $timer->reset();


?>

Notes

By design, each MicroTimer instance can only be started and stopped once, retaining all its internal data for later use.

Reuse a previously-created instance by using the reset() method.