2017 © Pedro Peláez
 

library phpbenchtime

A light benchmark timer class for PHP.

image

jsanc623/phpbenchtime

A light benchmark timer class for PHP.

  • Tuesday, November 21, 2017
  • by jsanc623
  • Repository
  • 3 Watchers
  • 24 Stars
  • 17,640 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 8 Versions
  • 4 % Grown

The README.md

PHPBenchTime v2.1.0

Latest Stable Version Total Downloads Monthly Downloads License Build Status SensioLabsInsight, (*1)

A light benchmark timer class for PHP. PHPBenchTime is quite simple to use and is loaded with functionality - including detailed summary data, easily readable source, a robust lap system and pause/unpause functionality., (*2)

Also, please check out my Python version of this package: PyBenchTime Python Package, (*3)

On Packagist

https://packagist.org/packages/jsanc623/phpbenchtime, (*4)

Methods

public start()
public end()
public reset()
public lap()
public summary()
public pause()
public unPause()
private endLap()
private getCurrentTime()

Properties

private startTime
private endTime
private pauseTime
private laps
private lapCount

Usage

You should see the Usage.php file in source for the best how to documentation. However, here's an overview:, (*5)

Load and initiate the PHPBenchTime Timer:, (*6)

require('PHPBenchTime.php');
use PHPBenchTime\Timer;
$T = new Timer;

That was easy! Now lets start a new timer:, (*7)

$T->start();

Then lets just sleep for 3 seconds:, (*8)

sleep(3);

Now, lets end the timer, and put results in $time:, (*9)

$time = $T->end();

When we end a timer, we receive an array back, containing the start time, end time and difference between start and end times:, (*10)

Array (
    [running] => false
    [start] => 1406146951.9998
    [end] => 1406146952.0638
    [total] => 0.0019998550415039
    [paused] => 0
    [laps] => Array (
        [0] => Array (
            [name] => start
            [start] => 1406146951.9998
            [end] => 1406146952.0018
            [total] => 0.0019998550415039
        )
    )
)

Advanced Usage : Laps

PHPBenchTime also allows you to set laps between code execution, which allows you to determine what part of your code is causing a bottleneck., (*11)

Let's sleep for a couple of seconds between laps:, (*12)

sleep(1);
$T->lap();
sleep(2);
$T->lap();

Now, let's end the timer:, (*13)

$time = $T->end();

Let's see the results:, (*14)

Array (
    [running] => false
    [start] => 1406146951.9998
    [end] => 1406146952.0638
    [total] => 0.063999891281128
    [paused] => 0.041000127792358
    [laps] => Array (
        [0] => Array (
            [name] => start
            [start] => 1406146951.9998
            [end] => 1406146952.0018
            [total] => 0.0019998550415039
        )
        [1] => Array (
            [name] => 1
            [start] => 1406146952.0018
            [end] => 1406146952.0028
            [total] => 0.0010001659393311
        )
        [2] => Array (
            [name] => 2
            [start] => 1406146952.0028
            [end] => 1406146952.0128
            [total] => 0.0099999904632568
        )
    )
)

Advanced Usage

PHPBenchTime allows you to do named laps, as well as to pause and unpause the timer (say you want to make a network call or a call out to the database, but don't want to include that time in your benchmark - pause and then unpause after you receive the network/database data)., (*15)

HISTORY

  • v1.0.0: Static Birth!
  • v1.1.0: Static Namespaces!
  • v1.2.0: Non-Static Namespaces!
  • v1.3.0: Laps! Laps! Laps!
  • v2.0.0: Complete rewrite, adds pause, unpause, central lap system and more detailed summary
  • v2.1.0: Performance enhancements, unit tests, etc

The Versions

21/11 2017

dev-master

9999999-dev

A light benchmark timer class for PHP.

  Sources   Download

MIT

by Juan Sanchez

timer stopwatch benchmark profiler benchtime

21/11 2017

2.1.2

2.1.2.0

A light benchmark timer class for PHP.

  Sources   Download

MIT

by Juan Sanchez

timer stopwatch benchmark profiler benchtime

08/12 2016

2.1.1

2.1.1.0

A light benchmark timer class for PHP.

  Sources   Download

MIT

by Juan Sanchez

timer stopwatch benchmark profiler benchtime

08/12 2016

dev-bugfixes-7616

dev-bugfixes-7616

A light benchmark timer class for PHP.

  Sources   Download

MIT

by Juan Sanchez

timer stopwatch benchmark profiler benchtime

06/07 2015

2.1.0

2.1.0.0

A light benchmark timer class for PHP.

  Sources   Download

MIT

by Juan Sanchez

timer stopwatch benchmark profiler benchtime

06/07 2015

dev-enhancements-7615

dev-enhancements-7615

A light benchmark timer class for PHP.

  Sources   Download

MIT

by Juan Sanchez

timer stopwatch benchmark profiler benchtime

06/07 2015

dev-bugfixes-7615

dev-bugfixes-7615

A light benchmark timer class for PHP.

  Sources   Download

MIT

by Juan Sanchez

timer stopwatch benchmark profiler benchtime

23/07 2014

2.0.0

2.0.0.0

A light benchmark timer class for PHP.

  Sources   Download

MIT

by Juan Sanchez

timer stopwatch benchmark profiler benchtime