Simple PHP code time measurement

Fund package maintenance!

1.0.1 2022-06-09 07:34 UTC

This package is auto-updated.

Last update: 2024-06-09 12:25:10 UTC


PHP from Packagist Codacy Badge Latest Stable Version Total Downloads License


Simple PHP code time measurement. Using time units allows receiving information about the start time and end time of a unit and also its execution length in total seconds and in percent.

If angle/chrono is the easiest way, this is the second easiest.


This library is made for the use with Composer. Add it to your project by running $ composer require bitandblack/measurement.


Set up a new Measurement object once:


use BitAndBlack\Measurement\Measurement;

$measurement = new Measurement();

Create a Unit object for every part you want to measure, add it to the measurement object and start the measurement:


use BitAndBlack\Measurement\Unit;

$unit = new Unit('Sample Unit');


When you want to end the measurement of a unit, call $unit->end().

To receive the information about all your units, call $measurement->getSummary(). In out example, this would get something like:

    [0] => Array
            [description] => Sample Unit
            [started] => object(DateTime) // 2022-07-04 07:08:38.032900
            [ended] => object(DateTime) // 2022-07-04 07:08:40.035100
            [tookTime] => 2.0021901130676
            [tookPercent] => 100

Each unit object stores its own information, that can be access by regular getter methods. So you can access them for example like that:


var_dump('Sample Unit took ' . $unit->getTime() . ' seconds.');


If you have any questions, feel free to contact us under

Further information about Bit&Black can be found under