2017 © Pedro Peláez
 

library phptimer

Native PHP Library to profile PHP code.

image

ktamas77/phptimer

Native PHP Library to profile PHP code.

  • Tuesday, May 24, 2016
  • by ktamas77
  • Repository
  • 1 Watchers
  • 6 Stars
  • 29,013 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 43 % Grown

The README.md

PHPTimer

Note: v2.0.0 requires PHP 7.3 and using its own namespace., (*1)

For PHP 5 projects please use v1.0.0, (*2)

An easy to use 100% native PHP library to profile PHP code., (*3)

You can start/stop timers at any point in the code., (*4)

v2.0.0 use for PHP 7.3+:

Installation:, (*5)

composer require ktamas77/phptimer

Use in code:, (*6)

use ktamas77\phptimer\Timer;

v1.0.0 (legacy) use for PHP 5:

Installation:, (*7)

composer require ktamas77/phptimer:1.0.0

Use in code:, (*8)

<php

require_once 'timer.class.inc.php';

Example use:

$timer = new Timer();

$timer->start('cycle');
    for ($i = 0; $i < 100000; $i++) {
    $a *= $i;
}
$timer->stop('cycle');

for ($i = 0; $i < 10; $i++) {
    $timer->start("subloop");
    for ($j = 0; $j < 1000000; $j++) {
        $a = $i * $j;
    }
    $timer->stop("subloop");
}  

var_dump($timer->getAll());

Result:, (*9)

php timer_example.php 

array(3) {
  ["cycle"]=>
  array(8) {
    ["start"]=>
    float(1464109111.9151)
    ["stop"]=>
    float(1464109111.9188)
    ["starts"]=>
    int(1)
    ["range"]=>
    float(0.0037481784820557)
    ["status"]=>
    string(7) "stopped"
    ["average"]=>
    float(0.0037481784820557)
    ["average_human"]=>
    string(4) "0.00"
    ["range_human"]=>
    string(4) "0.00"
  }
  ["date"]=>
  array(8) {
    ["start"]=>
    float(1464109111.9189)
    ["stop"]=>
    float(1464109112.2928)
    ["starts"]=>
    int(1)
    ["range"]=>
    float(0.37390089035034)
    ["status"]=>
    string(7) "stopped"
    ["average"]=>
    float(0.37390089035034)
    ["average_human"]=>
    string(4) "0.37"
    ["range_human"]=>
    string(4) "0.37"
  }
  ["subloop"]=>
  array(8) {
    ["start"]=>
    float(1464109112.5907)
    ["stop"]=>
    float(1464109112.6227)
    ["starts"]=>
    int(10)
    ["range"]=>
    float(0.32978487014771)
    ["status"]=>
    string(7) "stopped"
    ["average"]=>
    float(0.032978487014771)
    ["average_human"]=>
    string(4) "0.03"
    ["range_human"]=>
    string(4) "0.33"
  }
}

The Versions

24/05 2016

dev-master

9999999-dev

Native PHP Library to profile PHP code.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Tamas Kalman

timer profiler

24/05 2016

1.0.0

1.0.0.0

Native PHP Library to profile PHP code.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Tamas Kalman

timer profiler