Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ? phpcs.diff.txt
- Index: Benchmark/Iterate.php
- ===================================================================
- RCS file: /repository/pear/Benchmark/Benchmark/Iterate.php,v
- retrieving revision 1.1
- diff -u -r1.1 Iterate.php
- --- Benchmark/Iterate.php 24 May 2007 05:17:56 -0000 1.1
- +++ Benchmark/Iterate.php 12 Oct 2008 11:51:24 -0000
- @@ -1,21 +1,27 @@
- <?php
- -//
- -// +------------------------------------------------------------------------+
- -// | PEAR :: Benchmark |
- -// +------------------------------------------------------------------------+
- -// | Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
- -// +------------------------------------------------------------------------+
- -// | This source file is subject to the New BSD license, That is bundled |
- -// | with this package in the file LICENSE, and is available through |
- -// | the world-wide-web at |
- -// | http://www.opensource.org/licenses/bsd-license.php |
- -// | If you did not receive a copy of the new BSDlicense and are unable |
- -// | to obtain it through the world-wide-web, please send a note to |
- -// | license@php.net so we can mail you a copy immediately. |
- -// +------------------------------------------------------------------------+
- -//
- -// $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
- -//
- +/**
- + * Iterate.php
- + *
- + * PHP version 4
- + *
- + * Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>.
- + *
- + * This source file is subject to the New BSD license, That is bundled
- + * with this package in the file LICENSE, and is available through
- + * the world-wide-web at
- + * http://www.opensource.org/licenses/bsd-license.php
- + * If you did not receive a copy of the new BSDlicense and are unable
- + * to obtain it through the world-wide-web, please send a note to
- + * license@php.net so we can mail you a copy immediately.
- + *
- + * @category Benchmarking
- + * @package Benchmark
- + * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- + * @version CVS: $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
- + * @link http://pear.php.net/package/Benchmark
- + */
- require_once 'Benchmark/Timer.php';
- @@ -79,38 +85,41 @@
- * ?>
- * </code>
- *
- - * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
- - * @copyright Copyright © 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
- - * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- * @category Benchmarking
- * @package Benchmark
- + * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- + * @link http://pear.php.net/package/Benchmark
- */
- -class Benchmark_Iterate extends Benchmark_Timer {
- +class Benchmark_Iterate extends Benchmark_Timer
- +{
- +
- /**
- * Benchmarks a function or method.
- *
- * @access public
- + * @return void
- */
- - function run() {
- + function run()
- + {
- $arguments = func_get_args();
- $iterations = array_shift($arguments);
- $function_name = array_shift($arguments);
- if (strstr($function_name, '::')) {
- - $function_name = explode('::', $function_name);
- - $objectmethod = $function_name[1];
- + $function_name = explode('::', $function_name);
- + $objectmethod = $function_name[1];
- }
- if (strstr($function_name, '->')) {
- - $function_name = explode('->', $function_name);
- - $objectname = $function_name[0];
- + list($objectname, $objectmethod) = explode('->', $function_name);
- $object = $GLOBALS[$objectname];
- - $objectmethod = $function_name[1];
- for ($i = 1; $i <= $iterations; $i++) {
- $this->setMarker('start_' . $i);
- - call_user_func_array(array($object, $function_name[1]), $arguments);
- + call_user_func_array(array($object, $objectmethod), $arguments);
- $this->setMarker('end_' . $i);
- }
- @@ -131,17 +140,20 @@
- * $result['mean' ] = mean execution time
- * $result['iterations'] = number of iterations
- *
- + * @param bool $simple_output Show just the total
- + *
- * @return array
- * @access public
- */
- - function get($simple_output = false) {
- + function get($simple_output = false)
- + {
- $result = array();
- $total = 0;
- $iterations = count($this->markers)/2;
- for ($i = 1; $i <= $iterations; $i++) {
- - $time = $this->timeElapsed('start_'.$i , 'end_'.$i);
- + $time = $this->timeElapsed('start_'.$i, 'end_'.$i);
- if (extension_loaded('bcmath')) {
- $total = bcadd($total, $time, 6);
- Index: Benchmark/Profiler.php
- ===================================================================
- RCS file: /repository/pear/Benchmark/Benchmark/Profiler.php,v
- retrieving revision 1.2
- diff -u -r1.2 Profiler.php
- --- Benchmark/Profiler.php 24 May 2007 05:23:20 -0000 1.2
- +++ Benchmark/Profiler.php 12 Oct 2008 11:51:24 -0000
- @@ -1,21 +1,27 @@
- <?php
- -//
- -// +----------------------------------------------------------------------+
- -// | PEAR :: Benchmark |
- -// +----------------------------------------------------------------------+
- -// | Copyright (c) 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>. |
- -// +----------------------------------------------------------------------+
- -// | This source file is subject to the New BSD license, That is bundled |
- -// | with this package in the file LICENSE, and is available through |
- -// | the world-wide-web at |
- -// | http://www.opensource.org/licenses/bsd-license.php |
- -// | If you did not receive a copy of the new BSDlicense and are unable |
- -// | to obtain it through the world-wide-web, please send a note to |
- -// | license@php.net so we can mail you a copy immediately. |
- -// +----------------------------------------------------------------------+
- -//
- -// $Id: Profiler.php,v 1.2 2007/05/24 05:23:20 anant Exp $
- -//
- +/**
- + * Benchmark
- + *
- + * PHP version 4
- + *
- + * 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>
- + *
- + * This source file is subject to the New BSD license, That is bundled
- + * with this package in the file LICENSE, and is available through
- + * the world-wide-web at
- + * http://www.opensource.org/licenses/bsd-license.php
- + * If you did not receive a copy of the new BSDlicense and are unable
- + * to obtain it through the world-wide-web, please send a note to
- + * license@php.net so we can mail you a copy immediately.
- + *
- + * @category Benchmarking
- + * @package Benchmark
- + * @author Matthias Englert <Matthias.Englert@gmx.de>
- + * @copyright 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>
- + * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- + * @version CVS: $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
- + * @link http://pear.php.net/package/Benchmark
- + */
- require_once 'PEAR.php';
- @@ -28,7 +34,7 @@
- * <?php
- * require_once 'Benchmark/Profiler.php';
- *
- - * $profiler = new Benchmark_Profiler(TRUE);
- + * $profiler = new Benchmark_Profiler(true);
- *
- * function myFunction() {
- * global $profiler;
- @@ -69,14 +75,17 @@
- * ?>
- * </code>
- *
- - * @author Matthias Englert <Matthias.Englert@gmx.de>
- - * @copyright Copyright © 2002-2005 Matthias Englert <Matthias.Englert@gmx.de>
- - * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- * @category Benchmarking
- * @package Benchmark
- + * @author Matthias Englert <Matthias.Englert@gmx.de>
- + * @copyright 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>
- + * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- + * @link http://pear.php.net/package/Benchmark
- * @since 1.2.0
- */
- -class Benchmark_Profiler extends PEAR {
- +class Benchmark_Profiler extends PEAR
- +{
- +
- /**
- * Contains the total ex. time of each section
- *
- @@ -131,7 +140,7 @@
- * @var boolean
- * @access private
- */
- - var $_auto = FALSE;
- + var $_auto = false;
- /**
- * Max marker name length for non-html output
- @@ -144,9 +153,12 @@
- /**
- * Constructor, starts profiling recording
- *
- + * @param bool $auto Automatically start benchmarking
- + *
- * @access public
- */
- - function Benchmark_Profiler($auto = FALSE) {
- + function Benchmark_Profiler($auto = false)
- + {
- $this->_auto = $auto;
- if ($this->_auto) {
- @@ -160,8 +172,10 @@
- * Close method, stop profiling recording and display output.
- *
- * @access public
- + * @return void
- */
- - function close() {
- + function close()
- + {
- if (isset($this->_auto) && $this->_auto) {
- $this->stop();
- $this->display();
- @@ -171,11 +185,13 @@
- /**
- * Returns profiling informations for a given section.
- *
- - * @param string $section
- + * @param string $section Section to retrieve
- + *
- * @return array
- * @access public
- */
- - function getSectionInformations($section = 'Global') {
- + function getSectionInformations($section = 'Global')
- + {
- if (isset($this->_sections[$section])) {
- $calls = array();
- @@ -191,38 +207,46 @@
- $informations = array();
- - $informations['time'] = $this->_sections[$section];
- if (isset($this->_sections['Global'])) {
- - $informations['percentage'] = number_format(100 * $this->_sections[$section] / $this->_sections['Global'], 2, '.', '');
- + $value = $this->_sections[$section] / $this->_sections['Global'];
- + $value = $value * 100;
- +
- + $informations['percentage'] = number_format($value, 2, '.', '');
- } else {
- $informations['percentage'] = 'N/A';
- }
- - $informations['calls'] = $calls;
- - $informations['num_calls'] = $this->_numberOfCalls[$section];
- - $informations['callers'] = $callers;
- -
- - if (isset($this->_subSectionsTime[$section])) {
- - $informations['netto_time'] = $this->_sections[$section] - $this->_subSectionsTime[$section];
- - } else {
- - $informations['netto_time'] = $this->_sections[$section];
- - }
- +
- + $informations['time'] = $this->_sections[$section];
- + $informations['calls'] = $calls;
- + $informations['num_calls'] = $this->_numberOfCalls[$section];
- + $informations['callers'] = $callers;
- +
- + $value = $this->_sections[$section];
- +
- + if (isset($this->_subSectionsTime[$section])) {
- + $value -= $this->_subSectionsTime[$section];
- + }
- +
- + $informations['netto_time'] = $value;
- return $informations;
- } else {
- - $this->raiseError("The section '$section' does not exists.\n", NULL, PEAR_ERROR_TRIGGER, E_USER_WARNING);
- + $this->raiseError("The section '$section' does not exists.\n",
- + null, PEAR_ERROR_TRIGGER, E_USER_WARNING);
- }
- }
- /**
- * Returns profiling informations for all sections.
- *
- - * @return array
- * @access public
- + * @return array
- */
- - function getAllSectionsInformations() {
- + function getAllSectionsInformations()
- + {
- $informations = array();
- - foreach($this->_sections as $section => $time) {
- + foreach ($this->_sections as $section => $time) {
- $informations[$section] = $this->getSectionInformations($section);
- }
- @@ -232,19 +256,22 @@
- /**
- * Returns formatted profiling information.
- *
- - * @param string output format (auto, plain or html), default auto
- + * @param string $format output format (auto, plain or html), default auto
- + *
- * @see display()
- * @access private
- + * @return string
- */
- - function _getOutput($format) {
- + function _getOutput($format)
- + {
- /* Quickly find out the maximun length: Ineffecient, but will do for now! */
- $informations = $this->getAllSectionsInformations();
- +
- $names = array_keys($informations);
- $maxLength = 0;
- - foreach ($names as $name)
- - {
- + foreach ($names as $name) {
- if ($maxLength < strlen($name)) {
- $maxLength = strlen($name);
- }
- @@ -257,20 +284,27 @@
- $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain';
- } else {
- global $HTTP_SERVER_VARS;
- - $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain';
- + $use_html = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']);
- +
- + $format = $use_html ? 'html' : 'plain';
- }
- }
- if ($format == 'html') {
- - $out = '<table style="border: 1px solid #000000; ">'."\n";
- + $out = '<table style="border: 1px solid #000000; ">'."\n";
- $out .=
- '<tr><td> </td><td align="center"><b>total ex. time</b></td>'.
- '<td align="center"><b>netto ex. time</b></td>'.
- - '<td align="center"><b>#calls</b></td><td align="center"><b>%</b></td>'.
- - '<td align="center"><b>calls</b></td><td align="center"><b>callers</b></td></tr>'.
- + '<td align="center"><b>#calls</b></td>'.
- + '<td align="center"><b>%</b></td>'.
- + '<td align="center"><b>calls</b></td>' .
- + '<td align="center"><b>callers</b></td></tr>'.
- "\n";
- } else {
- - $dashes = $out = str_pad("\n", ($this->_maxStringLength + 75), '-', STR_PAD_LEFT);
- + $dashes = str_pad("\n", ($this->_maxStringLength + 75), '-',
- + STR_PAD_LEFT);
- +
- + $out = $dashes;
- $out .= str_pad('Section', $this->_maxStringLength + 10);
- $out .= str_pad("Total Ex Time", 22);
- $out .= str_pad("Netto Ex Time", 22);
- @@ -279,11 +313,11 @@
- $out .= $dashes;
- }
- - foreach($informations as $name => $values) {
- + foreach ($informations as $name => $values) {
- $percentage = $values['percentage'];
- - $calls_str = "";
- + $calls_str = "";
- - foreach($values['calls'] as $key => $val) {
- + foreach ($values['calls'] as $key => $val) {
- if ($calls_str) {
- $calls_str .= ", ";
- }
- @@ -293,32 +327,35 @@
- $callers_str = "";
- - foreach($values['callers'] as $key => $val) {
- + foreach ($values['callers'] as $key => $val) {
- if ($callers_str) {
- $callers_str .= ", ";
- - }
- + }
- $callers_str .= "$key ($val)";
- }
- + $percentage = $values['percentage'];
- + if (is_numeric($values['percentage'])) {
- + $percentage .= '%';
- + }
- +
- if ($format == 'html') {
- - $out .= "<tr><td><b>$name</b></td><td>{$values['time']}</td><td>{$values['netto_time']}</td><td>{$values['num_calls']}</td>";
- - if (is_numeric($values['percentage'])) {
- - $out .= "<td align=\"right\">{$values['percentage']}%</td>\n";
- - } else {
- - $out .= "<td align=\"right\">{$values['percentage']}</td>\n";
- - }
- + $out .= "<tr>";
- + $out .= "<td><b>$name</b></td>";
- + $out .= "<td>{$values['time']}</td>";
- + $out .= "<td>{$values['netto_time']}</td>";
- + $out .= "<td>{$values['num_calls']}</td>";
- + $out .= "<td>{$percentage}</td>";
- +
- +
- $out .= "<td>$calls_str</td><td>$callers_str</td></tr>";
- } else {
- $out .= str_pad($name, $this->_maxStringLength + 10);
- $out .= str_pad($values['time'], 22);
- $out .= str_pad($values['netto_time'], 22);
- - $out .= str_pad($values['num_calls'], 10);
- - if (is_numeric($values['percentage'])) {
- - $out .= str_pad($values['percentage']."%\n", 8, ' ', STR_PAD_LEFT);
- - } else {
- - $out .= str_pad($values['percentage']."\n", 8, ' ', STR_PAD_LEFT);
- - }
- + $out .= str_pad($values['num_calls'], 10);
- + $out .= str_pad($percentage . "\n", 8, ' ', STR_PAD_LEFT);
- }
- }
- @@ -332,10 +369,13 @@
- /**
- * Returns formatted profiling information.
- *
- - * @param string output format (auto, plain or html), default auto
- + * @param string $format output format (auto, plain or html), default auto
- + *
- * @access public
- + * @return void
- */
- - function display($format = 'auto') {
- + function display($format = 'auto')
- + {
- echo $this->_getOutput($format);
- }
- @@ -344,8 +384,10 @@
- *
- * @see enterSection(), stop()
- * @access public
- + * @return void
- */
- - function start() {
- + function start()
- + {
- $this->enterSection('Global');
- }
- @@ -354,34 +396,44 @@
- *
- * @see leaveSection(), start()
- * @access public
- + * @return void
- */
- - function stop() {
- + function stop()
- + {
- $this->leaveSection('Global');
- }
- /**
- * Enters code section.
- *
- - * @param string name of the code section
- + * @param string $name The code section
- + *
- * @see start(), leaveSection()
- * @access public
- + * @return void
- */
- - function enterSection($name) {
- + function enterSection($name)
- + {
- if (count($this->_stack)) {
- - if (isset($this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]])) {
- - $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]]++;
- + $item = end($this->_stack);
- +
- + if (isset($this->_callers[$name][$item["name"]])) {
- + $this->_callers[$name][$item]++;
- } else {
- - $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]] = 1;
- + $this->_callers[$name][$item] = 1;
- }
- - if (isset($this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name])) {
- - $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name]++;
- + if (isset($this->_calls[$item][$name])) {
- + $this->_calls[$item["name"]][$name]++;
- } else {
- - $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name] = 1;
- + $this->_calls[$item["name"]][$name] = 1;
- }
- } else {
- if ($name != 'Global') {
- - $this->raiseError("tried to enter section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE);
- + $msg = "tried to enter section " . $name
- + . " but profiling was not started\n";
- +
- + $this->raiseError($msg, null, PEAR_ERROR_DIE);
- }
- }
- @@ -391,27 +443,37 @@
- $this->_numberOfCalls[$name] = 1;
- }
- - array_push($this->_stack, array("name" => $name, "time" => $this->_getMicrotime()));
- + $data = array("name" => $name, "time" => $this->_getMicrotime());
- + array_push($this->_stack, $data);
- }
- /**
- * Leaves code section.
- *
- - * @param string name of the marker to be set
- - * @see stop(), enterSection()
- + * @param string $name The marker to be set
- + *
- + * @see stop(), enterSection()
- * @access public
- + * @return void
- */
- - function leaveSection($name) {
- + function leaveSection($name)
- + {
- $microtime = $this->_getMicrotime();
- if (!count($this->_stack)) {
- - $this->raiseError("tried to leave section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE);
- + $msg = "tried to leave section " . $name
- + . " but profiling was not started\n";
- +
- + $this->raiseError($msg, null, PEAR_ERROR_DIE);
- }
- $x = array_pop($this->_stack);
- if ($x["name"] != $name) {
- - $this->raiseError("reached end of section $name but expecting end of " . $x["name"]."\n", NULL, PEAR_ERROR_DIE);
- + $msg = "reached end of section " . $name
- + . " but expecting end of " . $x["name"] . "\n";
- +
- + $this->raiseError($msg, null, PEAR_ERROR_DIE);
- }
- if (isset($this->_sections[$name])) {
- @@ -422,7 +484,7 @@
- $parent = array_pop($this->_stack);
- - if (isset($parent)) {
- + if (isset($parent)) {
- if (isset($this->_subSectionsTime[$parent['name']])) {
- $this->_subSectionsTime[$parent['name']] += $microtime - $x['time'];
- } else {
- @@ -440,7 +502,8 @@
- * @access private
- * @since 1.3.0
- */
- - function _getMicrotime() {
- + function _getMicrotime()
- + {
- $microtime = explode(' ', microtime());
- return $microtime[1] . substr($microtime[0], 1);
- }
- Index: Benchmark/Timer.php
- ===================================================================
- RCS file: /repository/pear/Benchmark/Benchmark/Timer.php,v
- retrieving revision 1.2
- diff -u -r1.2 Timer.php
- --- Benchmark/Timer.php 24 May 2007 05:23:20 -0000 1.2
- +++ Benchmark/Timer.php 12 Oct 2008 11:51:24 -0000
- @@ -1,22 +1,27 @@
- <?php
- -//
- -// +------------------------------------------------------------------------+
- -// | PEAR :: Benchmark |
- -// +------------------------------------------------------------------------+
- -// | Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
- -// +------------------------------------------------------------------------+
- -// | This source file is subject to the New BSD license, That is bundled |
- -// | with this package in the file LICENSE, and is available through |
- -// | the world-wide-web at |
- -// | http://www.opensource.org/licenses/bsd-license.php |
- -// | If you did not receive a copy of the new BSDlicense and are unable |
- -// | to obtain it through the world-wide-web, please send a note to |
- -// | license@php.net so we can mail you a copy immediately. |
- -// +------------------------------------------------------------------------+
- -//
- -// $Id: Timer.php,v 1.2 2007/05/24 05:23:20 anant Exp $
- -//
- -
- +/**
- + * Timer.php
- + *
- + * PHP version 4
- + *
- + * Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>.
- + *
- + * This source file is subject to the New BSD license, That is bundled
- + * with this package in the file LICENSE, and is available through
- + * the world-wide-web at
- + * http://www.opensource.org/licenses/bsd-license.php
- + * If you did not receive a copy of the new BSDlicense and are unable
- + * to obtain it through the world-wide-web, please send a note to
- + * license@php.net so we can mail you a copy immediately.
- + *
- + * @category Benchmarking
- + * @package Benchmark
- + * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- + * @version CVS: $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
- + * @link http://pear.php.net/package/Benchmark
- + */
- require_once 'PEAR.php';
- /**
- @@ -46,18 +51,20 @@
- *
- * $timer->display(); // to output html formated
- * // AND/OR :
- - * $profiling = $timer->getProfiling(); // get the profiler info as an associative array
- + * $profiling = $timer->getProfiling(); // get profiler info as associative array
- * ?>
- * </code>
- *
- + * @category Benchmarking
- + * @package Benchmark
- * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
- * @author Ludovico Magnocavallo <ludo@sumatrasolutions.com>
- - * @copyright Copyright © 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
- * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- - * @category Benchmarking
- - * @package Benchmark
- + * @link http://pear.php.net/package/Benchmark
- */
- -class Benchmark_Timer extends PEAR {
- +class Benchmark_Timer extends PEAR
- +{
- /**
- * Contains the markers.
- *
- @@ -72,7 +79,7 @@
- * @var boolean
- * @access private
- */
- - var $auto = FALSE;
- + var $auto = false;
- /**
- * Max marker name length for non-html output.
- @@ -85,10 +92,12 @@
- /**
- * Constructor.
- *
- - * @param boolean $auto
- + * @param boolean $auto Automatically start timer
- + *
- * @access public
- */
- - function Benchmark_Timer($auto = FALSE) {
- + function Benchmark_Timer($auto = false)
- + {
- $this->auto = $auto;
- if ($this->auto) {
- @@ -102,8 +111,10 @@
- * Close method. Stop timer and display output.
- *
- * @access public
- + * @return void
- */
- - function close() {
- + function close()
- + {
- if ($this->auto) {
- $this->stop();
- $this->display();
- @@ -115,8 +126,10 @@
- *
- * @see setMarker(), stop()
- * @access public
- + * @return void
- */
- - function start() {
- + function start()
- + {
- $this->setMarker('Start');
- }
- @@ -125,35 +138,42 @@
- *
- * @see setMarker(), start()
- * @access public
- + * @return void
- */
- - function stop() {
- + function stop()
- + {
- $this->setMarker('Stop');
- }
- /**
- * Set marker.
- *
- - * @param string $name Name of the marker to be set.
- + * @param string $name Name of the marker to be set.
- + *
- * @see start(), stop()
- * @access public
- + * @return void
- */
- - function setMarker($name) {
- + function setMarker($name)
- + {
- $this->markers[$name] = $this->_getMicrotime();
- }
- /**
- * Returns the time elapsed betweens two markers.
- *
- - * @param string $start start marker, defaults to "Start"
- - * @param string $end end marker, defaults to "Stop"
- + * @param string $start start marker, defaults to "Start"
- + * @param string $end end marker, defaults to "Stop"
- + *
- * @return double $time_elapsed time elapsed between $start and $end
- * @access public
- */
- - function timeElapsed($start = 'Start', $end = 'Stop') {
- + function timeElapsed($start = 'Start', $end = 'Stop')
- + {
- if ($end == 'Stop' && !isset($this->markers['Stop'])) {
- $this->markers['Stop'] = $this->_getMicrotime();
- }
- - $end = isset($this->markers[$end]) ? $this->markers[$end] : 0;
- + $end = isset($this->markers[$end]) ? $this->markers[$end] : 0;
- $start = isset($this->markers[$start]) ? $this->markers[$start] : 0;
- if (extension_loaded('bcmath')) {
- @@ -174,10 +194,13 @@
- * @return array
- * @access public
- */
- - function getProfiling() {
- + function getProfiling()
- + {
- $i = $total = 0;
- +
- $result = array();
- - $temp = reset($this->markers);
- + $temp = reset($this->markers);
- +
- $this->maxStringLength = 0;
- foreach ($this->markers as $marker => $time) {
- @@ -194,15 +217,25 @@
- $result[$i]['diff'] = $diff;
- $result[$i]['total'] = $total;
- - $this->maxStringLength = (strlen($marker) > $this->maxStringLength ? strlen($marker) + 1 : $this->maxStringLength);
- + $longer = strlen($marker) > $this->maxStringLength;
- +
- + if ($longer) {
- + $this->maxStringLength = strlen($marker) + 1;
- + }
- $temp = $time;
- $i++;
- }
- - $result[0]['diff'] = '-';
- + $result[0]['diff'] = '-';
- $result[0]['total'] = '-';
- - $this->maxStringLength = (strlen('total') > $this->maxStringLength ? strlen('total') : $this->maxStringLength);
- +
- + $longer = strlen('total') > $this->maxStringLength;
- +
- + if ($longer) {
- + $this->maxStringLength = strlen('total');
- + }
- +
- $this->maxStringLength += 2;
- return $result;
- @@ -211,22 +244,25 @@
- /**
- * Return formatted profiling information.
- *
- - * @param boolean $showTotal Optionnaly includes total in output, default no
- - * @param string $format output format (auto, plain or html), default auto
- + * @param boolean $showTotal Optionnaly includes total in output, default no
- + * @param string $format output format (auto, plain or html), default auto
- + *
- * @return string
- * @see getProfiling()
- * @access public
- */
- - function getOutput($showTotal = FALSE, $format = 'auto') {
- + function getOutput($showTotal = false, $format = 'auto')
- + {
- if ($format == 'auto') {
- if (function_exists('version_compare') &&
- - version_compare(phpversion(), '4.1', 'ge'))
- - {
- + version_compare(phpversion(), '4.1', 'ge')) {
- $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain';
- } else {
- global $HTTP_SERVER_VARS;
- - $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain';
- - }
- + $use_html = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']);
- +
- + $format = $use_html ? 'html' : 'plain';
- + }
- }
- $total = $this->TimeElapsed();
- @@ -234,14 +270,23 @@
- $dashes = '';
- if ($format == 'html') {
- - $out = '<table border="1">'."\n";
- - $out .= '<tr><td> </td><td align="center"><b>time index</b></td><td align="center"><b>ex time</b></td><td align="center"><b>%</b></td>'.
- - ($showTotal ?
- - '<td align="center"><b>elapsed</b></td><td align="center"><b>%</b></td>'
- - : '')."</tr>\n";
- + $out = '<table border="1">'."\n";
- + $out .= '<tr>';
- + $out .= '<td> </td>';
- + $out .= '<td align="center"><b>time index</b></td>';
- + $out .= '<td align="center"><b>ex time</b></td>';
- + $out .= '<td align="center"><b>%</b></td>';
- +
- + if ($showTotal) {
- + $out .= '<td align="center"><b>elapsed</b></td>';
- + $out .= '<td align="center"><b>%</b></td>';
- + }
- +
- + $out .= "</tr>\n";
- } else {
- $dashes = $out = str_pad("\n",
- $this->maxStringLength + ($showTotal ? 70 : 45), '-', STR_PAD_LEFT);
- +
- $out .= str_pad('marker', $this->maxStringLength) .
- str_pad("time index", 22) .
- str_pad("ex time", 16) .
- @@ -251,15 +296,17 @@
- }
- foreach ($result as $k => $v) {
- - $perc = (($v['diff'] * 100) / $total);
- + $perc = (($v['diff'] * 100) / $total);
- $tperc = (($v['total'] * 100) / $total);
- + $percentage = number_format($perc, 2, '.', '')."%";
- +
- if ($format == 'html') {
- $out .= "<tr><td><b>" . $v['name'] .
- "</b></td><td>" . $v['time'] .
- "</td><td>" . $v['diff'] .
- - "</td><td align=\"right\">" . number_format($perc, 2, '.', '') .
- - "%</td>".
- + "</td><td align=\"right\">" . $percentage .
- + "</td>".
- ($showTotal ?
- "<td>" . $v['total'] .
- "</td><td align=\"right\">" .
- @@ -267,10 +314,12 @@
- "%</td>" : '').
- "</tr>\n";
- } else {
- +
- +
- $out .= str_pad($v['name'], $this->maxStringLength, ' ') .
- str_pad($v['time'], 22) .
- str_pad($v['diff'], 14) .
- - str_pad(number_format($perc, 2, '.', '')."%",8, ' ', STR_PAD_LEFT) .
- + str_pad($percentage, 8, ' ', STR_PAD_LEFT) .
- ($showTotal ? ' '.
- str_pad($v['total'], 14) .
- str_pad(number_format($tperc, 2, '.', '')."%",
- @@ -282,7 +331,13 @@
- }
- if ($format == 'html') {
- - $out .= "<tr style='background: silver;'><td><b>total</b></td><td>-</td><td>${total}</td><td>100.00%</td>".($showTotal ? "<td>-</td><td>-</td>" : "")."</tr>\n";
- + $out .= "<tr style='background: silver;'>";
- + $out .= "<td><b>total</b></td>";
- + $out .= "<td>-</td>";
- + $out .= "<td>${total}</td>";
- + $out .= "<td>100.00%</td>";
- + $out .= ($showTotal ? "<td>-</td><td>-</td>" : "");
- + $out .= "</tr>\n";
- $out .= "</table>\n";
- } else {
- $out .= str_pad('total', $this->maxStringLength);
- @@ -298,12 +353,15 @@
- /**
- * Prints the information returned by getOutput().
- *
- - * @param boolean $showTotal Optionnaly includes total in output, default no
- - * @param string $format output format (auto, plain or html), default auto
- + * @param boolean $showTotal Optionnaly includes total in output, default no
- + * @param string $format output format (auto, plain or html), default auto
- + *
- * @see getOutput()
- * @access public
- + * @return void
- */
- - function display($showTotal = FALSE, $format = 'auto') {
- + function display($showTotal = false, $format = 'auto')
- + {
- print $this->getOutput($showTotal, $format);
- }
- @@ -314,7 +372,8 @@
- * @access private
- * @since 1.3.0
- */
- - function _getMicrotime() {
- + function _getMicrotime()
- + {
- $microtime = explode(' ', microtime());
- return $microtime[1] . substr($microtime[0], 1);
- }
- Index: doc/timer_example.php
- ===================================================================
- RCS file: /repository/pear/Benchmark/doc/timer_example.php,v
- retrieving revision 1.4
- diff -u -r1.4 timer_example.php
- --- doc/timer_example.php 14 Apr 2006 14:10:43 -0000 1.4
- +++ doc/timer_example.php 12 Oct 2008 11:51:25 -0000
- @@ -1,11 +1,45 @@
- <?php
- +/**
- + * timer_example.php
- + *
- + * PHP version 4
- + *
- + * Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>.
- + *
- + * This source file is subject to the New BSD license, That is bundled
- + * with this package in the file LICENSE, and is available through
- + * the world-wide-web at
- + * http://www.opensource.org/licenses/bsd-license.php
- + * If you did not receive a copy of the new BSDlicense and are unable
- + * to obtain it through the world-wide-web, please send a note to
- + * license@php.net so we can mail you a copy immediately.
- + *
- + * @category Benchmarking
- + * @package Benchmark
- + * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
- + * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
- + * @version CVS: $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
- + * @link http://pear.php.net/package/Benchmark
- + */
- +
- require 'Benchmark/Timer.php';
- -function wait($amount) {
- +/**
- + * Wait
- + *
- + * @param int $amount Amount to wait
- + *
- + * @return void
- + */
- +function wait($amount)
- +{
- for ($i=0; $i < $amount; $i++) {
- - for ($i=0; $i < 100; $i++);
- + for ($i=0; $i < 100; $i++) {
- + }
- }
- }
- +
- // Pass the param "true" to constructor to automatically display the results
- $timer = new Benchmark_Timer();
- $timer->start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement