cmmarslender / timer
PHP Timer with optional per-item averages
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 2 191
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
This package is auto-updated.
Last update: 2021-12-18 11:53:33 UTC
README
PHP Timer w/ Average Time per Item
Installation
Install with composer composer require cmmarslender/timer
Usage
Simple - Tracking elapsed time
<?php use Cmmarslender\Timer as Timer; // Get a new Timer object $timer = new Timer(); // Start the timer $timer->start(); // Get elapsed time $timer->elapsed_time(); // Stop timer $timer->stop(); // Reset timer $timer->reset();
Advanced - Tracking time, averages, and percent complete
This example demonstrates how to use the timer to not only track time, but also average time per item and estimated remaining time, when you know how many items you have to process. In this example, we have 100 items to process. The ->tick()
method is called each time an item is processed, to let the timer know you are on to the next item.
<?php use Cmmarslender\Timer as Timer; // Get a new Timer object $timer = new Timer(); // Tell the timer we have 100 total items $timer->set_total_items( 100 ); // Start the timer $timer->start(); // Imaginary loop that processes you items foreach ( $items as $item ) { // Do something to the item $timer->tick(); // Get average time per item $average = $timer->average(); // Get estimated time remaining (based on average) $remaining = $timer->remaining_time(); // Get percent complete $percent = $timer->percent_complete(); }