Skip to content
Snippets Groups Projects
Commit 07fef6be authored by Prach Pongpanich's avatar Prach Pongpanich
Browse files

Imported Upstream version 1.0.5

parent e3faa4f0
No related branches found
No related tags found
No related merge requests found
PHP_Timer 1.0
=============
This is the list of changes for the PHP_Timer 1.0 release series.
PHP_Timer 1.0.1
---------------
* No changes.
PHP_Timer
=========
Installation
------------
PHP_Timer should be installed using the [PEAR Installer](http://pear.php.net/). This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0.
The PEAR channel (`pear.phpunit.de`) that is used to distribute PHP_Timer needs to be registered with the local PEAR environment:
sb@ubuntu ~ % pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded
This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:
sb@vmware ~ % pear install phpunit/PHP_Timer
downloading PHP_Timer-1.0.0.tgz ...
Starting to download PHP_Timer-1.0.0.tgz (2,536 bytes)
....done: 2,536 bytes
install ok: channel://pear.phpunit.de/PHP_Timer-1.0.0
After the installation you can find the PHP_Timer source files inside your local PEAR directory; the path is usually `/usr/lib/php/PHP`.
PHP_Timer
Copyright (c) 2010-2011, Sebastian Bergmann <sebastian@phpunit.de>.
Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
......
......@@ -2,7 +2,7 @@
/**
* PHP_Timer
*
* Copyright (c) 2010-2011, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -36,9 +36,9 @@
*
* @package PHP
* @subpackage Timer
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://github.com/sebastianbergmann/php-timer
* @since File available since Release 1.0.0
*/
......@@ -48,10 +48,10 @@
*
* @package PHP
* @subpackage Timer
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: 1.0.2
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @version Release: 1.0.5
* @link http://github.com/sebastianbergmann/php-timer
* @since Class available since Release 1.0.0
*/
......@@ -60,7 +60,16 @@ class PHP_Timer
/**
* @var array
*/
protected static $startTimes = array();
private static $times = array(
'hour' => 3600000,
'minute' => 60000,
'second' => 1000
);
/**
* @var array
*/
private static $startTimes = array();
/**
* @var float
......@@ -93,32 +102,16 @@ class PHP_Timer
*/
public static function secondsToTimeString($time)
{
$buffer = '';
$hours = sprintf('%02d', ($time >= 3600) ? floor($time / 3600) : 0);
$minutes = sprintf(
'%02d',
($time >= 60) ? floor($time / 60) - 60 * $hours : 0
);
$seconds = sprintf('%02d', $time - 60 * 60 * $hours - 60 * $minutes);
if ($hours == 0 && $minutes == 0) {
$seconds = sprintf('%1d', $seconds);
$ms = round($time * 1000);
$buffer .= $seconds . ' second';
if ($seconds != '1') {
$buffer .= 's';
}
} else {
if ($hours > 0) {
$buffer = $hours . ':';
foreach (self::$times as $unit => $value) {
if ($ms >= $value) {
$time = floor($ms / $value * 100.0) / 100.0;
return $time . ' ' . ($time == 1 ? $unit : $unit . 's');
}
$buffer .= $minutes . ':' . $seconds;
}
return $buffer;
return $ms . ' ms';
}
/**
......@@ -128,7 +121,7 @@ class PHP_Timer
*/
public static function timeSinceStartOfRequest()
{
return self::secondsToTimeString(time() - self::$requestTime);
return self::secondsToTimeString(microtime(TRUE) - self::$requestTime);
}
/**
......@@ -146,8 +139,10 @@ class PHP_Timer
}
}
if (isset($_SERVER['REQUEST_TIME'])) {
PHP_Timer::$requestTime = $_SERVER['REQUEST_TIME'];
} else {
PHP_Timer::$requestTime = time();
if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
PHP_Timer::$requestTime = $_SERVER['REQUEST_TIME_FLOAT'];
}
else {
PHP_Timer::$requestTime = microtime(TRUE);
}
......@@ -2,7 +2,7 @@
/**
* PHP_Timer
*
* Copyright (c) 2010-2011, Sebastian Bergmann <sb@sebastian-bergmann.de>.
* Copyright (c) 2010-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -36,40 +36,31 @@
*
* @package PHP
* @subpackage Timer
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2010-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2010-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://github.com/sebastianbergmann/php-timer
* @since File available since Release 1.1.0
*/
function php_timer_autoload($class = NULL) {
static $classes = NULL;
static $path = NULL;
spl_autoload_register(
function ($class)
{
static $classes = NULL;
static $path = NULL;
if ($classes === NULL) {
$classes = array(
'php_timer' => '/Timer.php'
);
if ($classes === NULL) {
$classes = array(
'php_timer' => '/Timer.php'
);
$path = dirname(dirname(__FILE__));
}
$path = dirname(dirname(__FILE__));
}
if ($class === NULL) {
$result = array(__FILE__);
$cn = strtolower($class);
foreach ($classes as $file) {
$result[] = $path . $file;
}
return $result;
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require $path . $classes[$cn];
}
}
spl_autoload_register('php_timer_autoload');
if (isset($classes[$cn])) {
require $path . $classes[$cn];
}
}
);
# PHP_Timer
Utility class for timing things, factored out of PHPUnit into a stand-alone component.
## Installation
You can use the [PEAR Installer](http://pear.php.net/manual/en/guide.users.commandline.cli.php) or [Composer](http://getcomposer.org/) to download and install this package as well as its dependencies.
### PEAR Installer
The following two commands (which you may have to run as `root`) are all that is required to install this package using the PEAR Installer:
pear config-set auto_discover 1
pear install pear.phpunit.de/PHP_Timer
### Composer
To add this package as a local, per-project dependency to your project, simply add a dependency on `phpunit/php-timer` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on PHP_Timer:
{
"require": {
"phpunit/php-timer": "*"
}
}
### Usage
#### Basic Timing
```php
PHP_Timer::start();
$timer->start();
// ...
$time = PHP_Timer::stop();
var_dump($time);
print PHP_Timer::secondsToTimeString($time);
```
The code above yields the output below:
double(1.0967254638672E-5)
0 ms
#### Resource Consumption Since PHP Startup
```php
print PHP_Timer::resourceUsage();
```
The code above yields the output below:
Time: 0 ms, Memory: 0.50Mb
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Version: GnuPG v1.4.13 (GNU/Linux)
iEYEABECAAYFAk5nV7EACgkQaGfFFLhbXWl0IQCfWT/2Uw7HqTgWfa7r4WQ/7tMD
gk4AnArN3rLfZqj/UwHBGmgMPebI+Lki
=LjcT
iEYEABECAAYFAlH7YtUACgkQaGfFFLhbXWk4dwCghxAldGTjOWA9sjxH/JOEgFZ2
IfAAniU4eEHBu2AwY2jIebQTyvr6ogBq
=+RPO
-----END PGP SIGNATURE-----
......@@ -10,37 +10,36 @@
<email>sb@sebastian-bergmann.de</email>
<active>yes</active>
</lead>
<date>2011-09-07</date>
<time>11:38:14</time>
<date>2013-08-02</date>
<time>07:42:08</time>
<version>
<release>1.0.2</release>
<release>1.0.5</release>
<api>1.0.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license>BSD License</license>
<license>The BSD 3-Clause License</license>
<notes>
http://github.com/sebastianbergmann/php-timer/blob/master/README.markdown
</notes>
<contents>
<dir name="/">
<file baseinstalldir="/" md5sum="373bbb5f3fce44d82646b25cdf58e7dd" name="PHP/Timer/Autoload.php" role="php">
<file baseinstalldir="/" md5sum="29ee3ab408bf7b576d4a117a5feb8912" name="PHP/Timer/Autoload.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
<file baseinstalldir="/" md5sum="f69722829638a2d1fabdab4dd2b6c854" name="PHP/Timer.php" role="php">
<file baseinstalldir="/" md5sum="73dbb7c1dd4fdea0a97cc59d4cfa40c7" name="PHP/Timer.php" role="php">
<tasks:replace from="@package_version@" to="version" type="package-info" />
</file>
<file baseinstalldir="/" md5sum="a3f8a544a1b539cee54a07e3ec7afa5d" name="ChangeLog.markdown" role="doc" />
<file baseinstalldir="/" md5sum="ee64ef6972cbb7aff5bf2211726fd750" name="LICENSE" role="doc" />
<file baseinstalldir="/" md5sum="5bfbe245c2c30b5f6e140f930a96e4c6" name="README.markdown" role="doc" />
<file baseinstalldir="/" md5sum="327ee3e3abeda7c7a9605889eee50e7e" name="LICENSE" role="doc" />
<file baseinstalldir="/" md5sum="731a603303de8707841e1c3b83501793" name="README.md" role="doc" />
</dir>
</contents>
<dependencies>
<required>
<php>
<min>5.2.7</min>
<min>5.3.3</min>
</php>
<pearinstaller>
<min>1.9.2</min>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment