2017 © Pedro Peláez
 

library php-timer

Utility class for timing

image

phpunit/php-timer

Utility class for timing

  • PHP
  • 69 Dependents
  • 10 Suggesters
  • 43 Forks
  • 0 Open issues
  • 10 Versions
  • 8 % Grown

The README.md

phpunit/php-timer

Latest Stable Version CI Status codecov, (*1)

Utility class for timing things, factored out of PHPUnit into a stand-alone component., (*2)

Installation

You can add this library as a local, per-project dependency to your project using Composer:, (*3)

composer require phpunit/php-timer

If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:, (*4)

composer require --dev phpunit/php-timer

Usage

Basic Timing

require __DIR__ . '/vendor/autoload.php';

use SebastianBergmann\Timer\Timer;

$timer = new Timer;

$timer->start();

foreach (\range(0, 100000) as $i) {
    // ...
}

$duration = $timer->stop();

var_dump(get_class($duration));
var_dump($duration->asString());
var_dump($duration->asSeconds());
var_dump($duration->asMilliseconds());
var_dump($duration->asMicroseconds());
var_dump($duration->asNanoseconds());

The code above yields the output below:, (*5)

string(32) "SebastianBergmann\Timer\Duration"
string(9) "00:00.002"
float(0.002851062)
float(2.851062)
float(2851.062)
int(2851062)

Resource Consumption

Explicit duration

require __DIR__ . '/vendor/autoload.php';

use SebastianBergmann\Timer\ResourceUsageFormatter;
use SebastianBergmann\Timer\Timer;

$timer = new Timer;
$timer->start();

foreach (\range(0, 100000) as $i) {
    // ...
}

print (new ResourceUsageFormatter)->resourceUsage($timer->stop());

The code above yields the output below:, (*6)

Time: 00:00.002, Memory: 6.00 MB

Duration since PHP Startup (using unreliable $_SERVER['REQUEST_TIME_FLOAT'])

require __DIR__ . '/vendor/autoload.php';

use SebastianBergmann\Timer\ResourceUsageFormatter;

foreach (\range(0, 100000) as $i) {
    // ...
}

print (new ResourceUsageFormatter)->resourceUsageSinceStartOfRequest();

The code above yields the output below:, (*7)

Time: 00:00.002, Memory: 6.00 MB

The Versions

04/06 2018

dev-master

9999999-dev https://github.com/sebastianbergmann/php-timer/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.1

 

The Development Requires

timer

01/02 2018

2.0.0

2.0.0.0 https://github.com/sebastianbergmann/php-timer/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php ^7.1

 

The Development Requires

timer

06/01 2018

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/sebastianbergmann/php-timer/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php ^5.3.3 || ^7.0

 

The Development Requires

timer

26/02 2017

1.0.9

1.0.9.0 https://github.com/sebastianbergmann/php-timer/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php ^5.3.3 || ^7.0

 

The Development Requires

timer

12/05 2016

1.0.8

1.0.8.0 https://github.com/sebastianbergmann/php-timer/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

The Development Requires

timer

21/06 2015

1.0.7

1.0.7.0 https://github.com/sebastianbergmann/php-timer/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

timer

13/06 2015

1.0.6

1.0.6.0 https://github.com/sebastianbergmann/php-timer/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

timer

02/08 2013

1.0.5

1.0.5.0 https://github.com/sebastianbergmann/php-timer/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

timer

11/10 2012

1.0.4

1.0.4.0 http://www.phpunit.de/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.3

 

timer

23/09 2012

1.0.3

1.0.3.0 http://www.phpunit.de/

Utility class for timing

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2.7

 

timer