bitandblack / measurement
Simple PHP code time measurement
Requires
- php: >=7.2
Requires (Dev)
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8.0 || ^9.0
This package is auto-updated.
Last update: 2021-03-27 13:43:33 UTC
README
Measurement
Simple PHP code time measurement. Using time units allows to receive 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.
Installation
This library is made for the use with Composer. Add it to your project by running $ composer require bitandblack/measurement
.
Usage
Set up a new Measurement object once:
<?php
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:
<?php
use BitAndBlack\Measurement\Unit;
$unit = new Unit('Some Description');
$measurement->add(
$unit->start()
);
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:
Array
(
[0] => Array
(
[description] => Some Description
[started] => 2019-07-04 07:08:38.032900
[ended] => 2019-07-04 07:08:40.035100
[tookTime] => 2.0021901130676
[tookPercent] => 100
)
)
All of this information have their own getter method, so you can access them for example by calling $unit->getTime()
.
Help
If you have any questions feel free to contact us under hello@bitandblack.com
.