PHP Classes

MycroBench: Measure the time that passed since a past moment

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2022-09-12 (13 days ago) RSS 2.0 feedNot enough user ratingsTotal: 24 This week: 1All time: 10,682 This week: 142Up
Version License PHP version Categories
mycrobench 1.0.1MIT/X Consortium ...7.4Time and Date, Performance and optimi..., P...
Description Author

This class can measure the time that has passed since a past moment.

It can get the current time and calculate the difference between the time that passed since the initial moment the class started keeping track of the time or since the last moment the course took note of the time.

The class can return an array that specifies the current time, the reference moment time, the timestamp for the present time, and the number of seconds that have passed since the reference moment.

Picture of Engin Ypsilon
Name: Engin Ypsilon <contact>
Classes: 4 packages by
Country: Germany Germany
Age: 42
All time rank: 4241226 in Germany Germany
Week rank: 162 Up8 in Germany Germany Up
Innovation award
Innovation award
Nominee: 1x


MycroBench | Lightweight time measure tool for PHP

This class uses $_SERVER['REQUEST_TIME_FLOAT'] and current microtime() to calculate the difference that has passed between the two timestamps in microseconds.

See ./tests/mykrobench for examples.

composer require eypsilon/MycroBench

use Many\MycroBench;

 * @var array
(new MycroBench)->get()

// Array
// (
//     [start] => 2022-09-12 18:34:24.4330
//     [ended] => 2022-09-12 18:34:24.4368
//     [took] => 00.0038
//     [mem_usage] => 358.49 KB
//     [mem_peak] => 1.34 MB
//     [included_files_total] => 7
// )

Subsequent requests

Get the difference of multiple calls with corrected start times for each new call.

(new MycroBench)->getBenchDiff()

// [start] => 2022-09-12 18:34:24.4330
// [ended] => 2022-09-12 18:34:24.4356
// [took] => 00.0026

(new MycroBench)->getBenchDiff()

// [start] => 2022-09-12 18:34:24.4356
// [ended] => 2022-09-12 18:34:24.4362
// [took] => 00.0006

(new MycroBench)->getBenchDiff()

// [start] => 2022-09-12 18:34:24.4362
// [ended] => 2022-09-12 18:34:24.4367
// [took] => 00.0005


 * Datetime with microseconds
 * @return string '2022-09-01 17:14:48.5000'
(new MycroBench)->getDate('1662045288.5000') # 'U.u', 'Y-m-d H:i:s.u'

 * Formats datetime to timestamp with microseconds
 * @return string '1662045288.5000'
(new MycroBench)->getDateToMicro('2022-09-01 17:14:48.5000') # 'Y-m-d H:i:s.u', 'U.u'

 * Get timestamp with microseconds from the last request or null on first request.
 * Only available and updated, when (new MycroBench)->getBenchDiff() gets called
 * @return string|null '1662623500.7135'

 * Readable Bytes
 * @return string '379.67 KB'
  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file MycroBench.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagemykrobench (2 files)

  Files folder image Files  /  tests  /  mykrobench  
File Role Description
  Accessible without login Image file favicon.ico Icon Icon image
  Accessible without login Plain text file index.php Example Example script

 Version Control Unique User Downloads Download Rankings  
This week:1
All time:10,682
This week:142Up
User Comments (1)
For more information send a message to info at phpclasses dot org.