Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

CloCkWeRX

By: a guest on Oct 12th, 2008  |  syntax: None  |  size: 37.53 KB  |  views: 136  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ? phpcs.diff.txt
  2. Index: Benchmark/Iterate.php
  3. ===================================================================
  4. RCS file: /repository/pear/Benchmark/Benchmark/Iterate.php,v
  5. retrieving revision 1.1
  6. diff -u -r1.1 Iterate.php
  7. --- Benchmark/Iterate.php       24 May 2007 05:17:56 -0000      1.1
  8. +++ Benchmark/Iterate.php       12 Oct 2008 11:51:24 -0000
  9.  -1,21 +1,27 @@
  10.  <?php
  11. -//
  12. -// +------------------------------------------------------------------------+
  13. -// | PEAR :: Benchmark                                                      |
  14. -// +------------------------------------------------------------------------+
  15. -// | Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  16. -// +------------------------------------------------------------------------+
  17. -// | This source file is subject to the New BSD license, That is bundled    |
  18. -// | with this package in the file LICENSE, and is available through        |
  19. -// | the world-wide-web at                                                  |
  20. -// | http://www.opensource.org/licenses/bsd-license.php                     |
  21. -// | If you did not receive a copy of the new BSDlicense and are unable     |
  22. -// | to obtain it through the world-wide-web, please send a note to         |
  23. -// | license@php.net so we can mail you a copy immediately.                 |
  24. -// +------------------------------------------------------------------------+
  25. -//
  26. -// $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
  27. -//
  28. +/**
  29. + * Iterate.php                                                      
  30. + *
  31. + * PHP version 4
  32. + *
  33. + * Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>.
  34. + *
  35. + * This source file is subject to the New BSD license, That is bundled    
  36. + * with this package in the file LICENSE, and is available through        
  37. + * the world-wide-web at                                                  
  38. + * http://www.opensource.org/licenses/bsd-license.php                    
  39. + * If you did not receive a copy of the new BSDlicense and are unable    
  40. + * to obtain it through the world-wide-web, please send a note to        
  41. + * license@php.net so we can mail you a copy immediately.                
  42. + *
  43. + * @category  Benchmarking
  44. + * @package   Benchmark
  45. + * @author    Sebastian Bergmann <sb@sebastian-bergmann.de>
  46. + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  47. + * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  48. + * @version   CVS: $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
  49. + * @link      http://pear.php.net/package/Benchmark
  50. + */
  51.  
  52.  require_once 'Benchmark/Timer.php';
  53.  
  54.  -79,38 +85,41 @@
  55.   * ?>
  56.   * </code>
  57.   *
  58. - * @author    Sebastian Bergmann <sb@sebastian-bergmann.de>
  59. - * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  60. - * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  61.   * @category  Benchmarking
  62.   * @package   Benchmark
  63. + * @author    Sebastian Bergmann <sb@sebastian-bergmann.de>
  64. + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  65. + * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  66. + * @link      http://pear.php.net/package/Benchmark
  67.   */
  68. -class Benchmark_Iterate extends Benchmark_Timer {
  69. +class Benchmark_Iterate extends Benchmark_Timer
  70. +{
  71. +
  72.      /**
  73.       * Benchmarks a function or method.
  74.       *
  75.       * @access public
  76. +     * @return void
  77.       */
  78. -    function run() {
  79. +    function run()
  80. +    {
  81.          $arguments     = func_get_args();
  82.          $iterations    = array_shift($arguments);
  83.          $function_name = array_shift($arguments);
  84.  
  85.          if (strstr($function_name, '::')) {
  86. -          $function_name = explode('::', $function_name);
  87. -          $objectmethod = $function_name[1];
  88. +            $function_name = explode('::', $function_name);
  89. +            $objectmethod  = $function_name[1];
  90.          }
  91.  
  92.          if (strstr($function_name, '->')) {
  93. -            $function_name = explode('->', $function_name);
  94. -            $objectname = $function_name[0];
  95. +            list($objectname, $objectmethod) = explode('->', $function_name);
  96.  
  97.              $object = $GLOBALS[$objectname];
  98. -            $objectmethod = $function_name[1];
  99.  
  100.              for ($i = 1; $i <= $iterations; $i++) {
  101.                  $this->setMarker('start_' . $i);
  102. -                call_user_func_array(array($object, $function_name[1]), $arguments);
  103. +                call_user_func_array(array($object, $objectmethod), $arguments);
  104.                  $this->setMarker('end_' . $i);
  105.              }
  106.  
  107.  -131,17 +140,20 @@
  108.       * $result['mean'      ] = mean execution time
  109.       * $result['iterations'] = number of iterations
  110.       *
  111. +     * @param bool $simple_output Show just the total
  112. +     *
  113.       * @return array
  114.       * @access public
  115.       */
  116. -    function get($simple_output = false) {
  117. +    function get($simple_output = false)
  118. +    {
  119.          $result = array();
  120.          $total  = 0;
  121.  
  122.          $iterations = count($this->markers)/2;
  123.  
  124.          for ($i = 1; $i <= $iterations; $i++) {
  125. -            $time = $this->timeElapsed('start_'.$i , 'end_'.$i);
  126. +            $time = $this->timeElapsed('start_'.$i, 'end_'.$i);
  127.  
  128.              if (extension_loaded('bcmath')) {
  129.                  $total = bcadd($total, $time, 6);
  130. Index: Benchmark/Profiler.php
  131. ===================================================================
  132. RCS file: /repository/pear/Benchmark/Benchmark/Profiler.php,v
  133. retrieving revision 1.2
  134. diff -u -r1.2 Profiler.php
  135. --- Benchmark/Profiler.php      24 May 2007 05:23:20 -0000      1.2
  136. +++ Benchmark/Profiler.php      12 Oct 2008 11:51:24 -0000
  137.  -1,21 +1,27 @@
  138.  <?php
  139. -//
  140. -// +----------------------------------------------------------------------+
  141. -// | PEAR :: Benchmark                                                    |
  142. -// +----------------------------------------------------------------------+
  143. -// | Copyright (c) 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>.  |
  144. -// +----------------------------------------------------------------------+
  145. -// | This source file is subject to the New BSD license, That is bundled  |
  146. -// | with this package in the file LICENSE, and is available through      |
  147. -// | the world-wide-web at                                                |
  148. -// | http://www.opensource.org/licenses/bsd-license.php                   |
  149. -// | If you did not receive a copy of the new BSDlicense and are unable   |
  150. -// | to obtain it through the world-wide-web, please send a note to       |
  151. -// | license@php.net so we can mail you a copy immediately.               |
  152. -// +----------------------------------------------------------------------+
  153. -//
  154. -// $Id: Profiler.php,v 1.2 2007/05/24 05:23:20 anant Exp $
  155. -//
  156. +/**
  157. + * Benchmark                                                      
  158. + *
  159. + * PHP version 4
  160. + *
  161. + * 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>
  162. + *
  163. + * This source file is subject to the New BSD license, That is bundled    
  164. + * with this package in the file LICENSE, and is available through        
  165. + * the world-wide-web at                                                  
  166. + * http://www.opensource.org/licenses/bsd-license.php                    
  167. + * If you did not receive a copy of the new BSDlicense and are unable    
  168. + * to obtain it through the world-wide-web, please send a note to        
  169. + * license@php.net so we can mail you a copy immediately.                
  170. + *
  171. + * @category  Benchmarking
  172. + * @package   Benchmark
  173. + * @author    Matthias Englert <Matthias.Englert@gmx.de>
  174. + * @copyright 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>
  175. + * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  176. + * @version   CVS: $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
  177. + * @link      http://pear.php.net/package/Benchmark
  178. + */
  179.  
  180.  require_once 'PEAR.php';
  181.  
  182.  -28,7 +34,7 @@
  183.   * <?php
  184.   * require_once 'Benchmark/Profiler.php';
  185.   *
  186. - * $profiler = new Benchmark_Profiler(TRUE);
  187. + * $profiler = new Benchmark_Profiler(true);
  188.   *
  189.   * function myFunction() {
  190.   *     global $profiler;
  191.  -69,14 +75,17 @@
  192.   * ?>
  193.   * </code>
  194.   *
  195. - * @author    Matthias Englert <Matthias.Englert@gmx.de>
  196. - * @copyright Copyright &copy; 2002-2005 Matthias Englert <Matthias.Englert@gmx.de>
  197. - * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  198.   * @category  Benchmarking
  199.   * @package   Benchmark
  200. + * @author    Matthias Englert <Matthias.Englert@gmx.de>
  201. + * @copyright 2002-2006 Matthias Englert <Matthias.Englert@gmx.de>
  202. + * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  203. + * @link      http://pear.php.net/package/Benchmark
  204.   * @since     1.2.0
  205.   */
  206. -class Benchmark_Profiler extends PEAR {
  207. +class Benchmark_Profiler extends PEAR
  208. +{
  209. +
  210.      /**
  211.       * Contains the total ex. time of each section
  212.       *
  213.  -131,7 +140,7 @@
  214.       * @var    boolean
  215.       * @access private
  216.       */
  217. -    var $_auto = FALSE;
  218. +    var $_auto = false;
  219.  
  220.      /**
  221.       * Max marker name length for non-html output
  222.  -144,9 +153,12 @@
  223.      /**
  224.       * Constructor, starts profiling recording
  225.       *
  226. +     * @param bool $auto Automatically start benchmarking
  227. +     *
  228.       * @access public
  229.       */
  230. -    function Benchmark_Profiler($auto = FALSE) {
  231. +    function Benchmark_Profiler($auto = false)
  232. +    {
  233.          $this->_auto = $auto;
  234.  
  235.          if ($this->_auto) {
  236.  -160,8 +172,10 @@
  237.       * Close method, stop profiling recording and display output.
  238.       *
  239.       * @access public
  240. +     * @return void
  241.       */
  242. -    function close() {
  243. +    function close()
  244. +    {
  245.          if (isset($this->_auto) && $this->_auto) {
  246.              $this->stop();
  247.              $this->display();
  248.  -171,11 +185,13 @@
  249.      /**
  250.       * Returns profiling informations for a given section.
  251.       *
  252. -     * @param  string $section
  253. +     * @param string $section Section to retrieve
  254. +     *
  255.       * @return array
  256.       * @access public
  257.       */
  258. -    function getSectionInformations($section = 'Global') {
  259. +    function getSectionInformations($section = 'Global')
  260. +    {
  261.          if (isset($this->_sections[$section])) {
  262.              $calls = array();
  263.  
  264.  -191,38 +207,46 @@
  265.  
  266.              $informations = array();
  267.  
  268. -            $informations['time']       = $this->_sections[$section];
  269.              if (isset($this->_sections['Global'])) {
  270. -                $informations['percentage'] = number_format(100 * $this->_sections[$section] / $this->_sections['Global'], 2, '.', '');
  271. +                $value = $this->_sections[$section] / $this->_sections['Global'];
  272. +                $value = $value * 100;
  273. +
  274. +                $informations['percentage'] = number_format($value, 2, '.', '');
  275.              } else {
  276.                  $informations['percentage'] = 'N/A';
  277.              }
  278. -            $informations['calls']      = $calls;
  279. -            $informations['num_calls']  = $this->_numberOfCalls[$section];
  280. -            $informations['callers']    = $callers;
  281. -
  282. -           if (isset($this->_subSectionsTime[$section])) {
  283. -                $informations['netto_time'] = $this->_sections[$section] - $this->_subSectionsTime[$section];
  284. -           } else {
  285. -                $informations['netto_time'] = $this->_sections[$section];
  286. -           }
  287. +
  288. +            $informations['time']      = $this->_sections[$section];
  289. +            $informations['calls']     = $calls;
  290. +            $informations['num_calls'] = $this->_numberOfCalls[$section];
  291. +            $informations['callers']   = $callers;
  292. +
  293. +            $value = $this->_sections[$section];
  294. +
  295. +            if (isset($this->_subSectionsTime[$section])) {
  296. +                $value -= $this->_subSectionsTime[$section];
  297. +            }
  298. +
  299. +            $informations['netto_time'] = $value;
  300.  
  301.              return $informations;
  302.          } else {
  303. -            $this->raiseError("The section '$section' does not exists.\n", NULL, PEAR_ERROR_TRIGGER, E_USER_WARNING);
  304. +            $this->raiseError("The section '$section' does not exists.\n",
  305. +                              null, PEAR_ERROR_TRIGGER, E_USER_WARNING);
  306.          }
  307.      }
  308.  
  309.      /**
  310.       * Returns profiling informations for all sections.
  311.       *
  312. -     * @return array
  313.       * @access public
  314. +     * @return array
  315.       */
  316. -    function getAllSectionsInformations() {
  317. +    function getAllSectionsInformations()
  318. +    {
  319.          $informations = array();
  320.  
  321. -        foreach($this->_sections as $section => $time) {
  322. +        foreach ($this->_sections as $section => $time) {
  323.              $informations[$section] = $this->getSectionInformations($section);
  324.          }
  325.  
  326.  -232,19 +256,22 @@
  327.      /**
  328.       * Returns formatted profiling information.
  329.       *
  330. -     * @param  string output format (auto, plain or html), default auto
  331. +     * @param string $format output format (auto, plain or html), default auto
  332. +     *
  333.       * @see    display()
  334.       * @access private
  335. +     * @return string
  336.       */
  337. -    function _getOutput($format) {
  338. +    function _getOutput($format)
  339. +    {
  340.          
  341.          /* Quickly find out the maximun length: Ineffecient, but will do for now! */
  342.          $informations = $this->getAllSectionsInformations();
  343. +
  344.          $names = array_keys($informations);
  345.          
  346.          $maxLength = 0;
  347. -        foreach ($names as $name)
  348. -        {
  349. +        foreach ($names as $name) {
  350.              if ($maxLength < strlen($name)) {
  351.                  $maxLength = strlen($name);
  352.              }
  353.  -257,20 +284,27 @@
  354.                  $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain';
  355.              } else {
  356.                  global $HTTP_SERVER_VARS;
  357. -                $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain';
  358. +                $use_html = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']);
  359. +
  360. +                $format = $use_html ? 'html' : 'plain';
  361.              }
  362.          }
  363.  
  364.          if ($format == 'html') {
  365. -            $out = '<table style="border: 1px solid #000000; ">'."\n";
  366. +            $out  = '<table style="border: 1px solid #000000; ">'."\n";
  367.              $out .=
  368.                  '<tr><td>&nbsp;</td><td align="center"><b>total ex. time</b></td>'.
  369.                  '<td align="center"><b>netto ex. time</b></td>'.
  370. -                '<td align="center"><b>#calls</b></td><td align="center"><b>%</b></td>'.
  371. -                '<td align="center"><b>calls</b></td><td align="center"><b>callers</b></td></tr>'.
  372. +                '<td align="center"><b>#calls</b></td>'.
  373. +                '<td align="center"><b>%</b></td>'.
  374. +                '<td align="center"><b>calls</b></td>' .
  375. +                '<td align="center"><b>callers</b></td></tr>'.
  376.                  "\n";
  377.          } else {
  378. -            $dashes = $out = str_pad("\n", ($this->_maxStringLength + 75), '-', STR_PAD_LEFT);
  379. +            $dashes = str_pad("\n", ($this->_maxStringLength + 75), '-',
  380. +                              STR_PAD_LEFT);
  381. +
  382. +            $out  = $dashes;
  383.              $out .= str_pad('Section', $this->_maxStringLength + 10);
  384.              $out .= str_pad("Total Ex Time", 22);
  385.              $out .= str_pad("Netto Ex Time", 22);
  386.  -279,11 +313,11 @@
  387.              $out .= $dashes;
  388.          }
  389.            
  390. -        foreach($informations as $name => $values) {
  391. +        foreach ($informations as $name => $values) {
  392.              $percentage = $values['percentage'];
  393. -            $calls_str = "";
  394. +            $calls_str  = "";
  395.  
  396. -            foreach($values['calls'] as $key => $val) {
  397. +            foreach ($values['calls'] as $key => $val) {
  398.                  if ($calls_str) {
  399.                      $calls_str .= ", ";
  400.                  }
  401.  -293,32 +327,35 @@
  402.  
  403.              $callers_str = "";
  404.  
  405. -            foreach($values['callers'] as $key => $val) {
  406. +            foreach ($values['callers'] as $key => $val) {
  407.                  if ($callers_str) {
  408.                      $callers_str .= ", ";
  409. -                       }
  410. +                }
  411.  
  412.                  $callers_str .= "$key ($val)";
  413.              }
  414.  
  415. +            $percentage = $values['percentage'];
  416. +            if (is_numeric($values['percentage'])) {
  417. +                $percentage .= '%';
  418. +            }
  419. +
  420.              if ($format == 'html') {
  421. -                $out .= "<tr><td><b>$name</b></td><td>{$values['time']}</td><td>{$values['netto_time']}</td><td>{$values['num_calls']}</td>";
  422. -                if (is_numeric($values['percentage'])) {
  423. -                    $out .= "<td align=\"right\">{$values['percentage']}%</td>\n";
  424. -                } else {
  425. -                    $out .= "<td align=\"right\">{$values['percentage']}</td>\n";
  426. -                }
  427. +                $out .= "<tr>";
  428. +                $out .= "<td><b>$name</b></td>";
  429. +                $out .= "<td>{$values['time']}</td>";
  430. +                $out .= "<td>{$values['netto_time']}</td>";
  431. +                $out .= "<td>{$values['num_calls']}</td>";
  432. +                $out .= "<td>{$percentage}</td>";
  433. +                
  434. +
  435.                  $out .= "<td>$calls_str</td><td>$callers_str</td></tr>";
  436.              } else {
  437.                  $out .= str_pad($name, $this->_maxStringLength + 10);
  438.                  $out .= str_pad($values['time'], 22);
  439.                  $out .= str_pad($values['netto_time'], 22);
  440. -                $out .= str_pad($values['num_calls'], 10);
  441. -                if (is_numeric($values['percentage'])) {
  442. -                    $out .= str_pad($values['percentage']."%\n", 8, ' ', STR_PAD_LEFT);
  443. -                } else {
  444. -                    $out .= str_pad($values['percentage']."\n", 8, ' ', STR_PAD_LEFT);
  445. -                }
  446. +                $out .= str_pad($values['num_calls'], 10);            
  447. +                $out .= str_pad($percentage . "\n", 8, ' ', STR_PAD_LEFT);
  448.              }
  449.          }
  450.          
  451.  -332,10 +369,13 @@
  452.      /**
  453.       * Returns formatted profiling information.
  454.       *
  455. -     * @param  string output format (auto, plain or html), default auto
  456. +     * @param string $format output format (auto, plain or html), default auto
  457. +     *
  458.       * @access public
  459. +     * @return void
  460.       */
  461. -    function display($format = 'auto') {
  462. +    function display($format = 'auto')
  463. +    {
  464.          echo $this->_getOutput($format);
  465.      }
  466.  
  467.  -344,8 +384,10 @@
  468.       *
  469.       * @see    enterSection(), stop()
  470.       * @access public
  471. +     * @return void
  472.       */
  473. -    function start() {
  474. +    function start()
  475. +    {
  476.          $this->enterSection('Global');
  477.      }
  478.  
  479.  -354,34 +396,44 @@
  480.       *
  481.       * @see    leaveSection(), start()
  482.       * @access public
  483. +     * @return void
  484.       */
  485. -    function stop() {
  486. +    function stop()
  487. +    {
  488.          $this->leaveSection('Global');
  489.      }
  490.  
  491.      /**
  492.       * Enters code section.
  493.       *
  494. -     * @param  string  name of the code section
  495. +     * @param string $name The code section
  496. +     *
  497.       * @see    start(), leaveSection()
  498.       * @access public
  499. +     * @return void
  500.       */
  501. -    function enterSection($name) {
  502. +    function enterSection($name)
  503. +    {
  504.          if (count($this->_stack)) {
  505. -            if (isset($this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]])) {
  506. -                $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]]++;
  507. +            $item = end($this->_stack);
  508. +
  509. +            if (isset($this->_callers[$name][$item["name"]])) {
  510. +                $this->_callers[$name][$item]++;
  511.              } else {
  512. -                $this->_callers[$name][$this->_stack[count($this->_stack) - 1]["name"]] = 1;
  513. +                $this->_callers[$name][$item] = 1;
  514.              }
  515.  
  516. -            if (isset($this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name])) {
  517. -                $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name]++;
  518. +            if (isset($this->_calls[$item][$name])) {
  519. +                $this->_calls[$item["name"]][$name]++;
  520.              } else {
  521. -                $this->_calls[$this->_stack[count($this->_stack) - 1]["name"]][$name] = 1;
  522. +                $this->_calls[$item["name"]][$name] = 1;
  523.              }
  524.          } else {
  525.              if ($name != 'Global') {
  526. -                $this->raiseError("tried to enter section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE);
  527. +                $msg = "tried to enter section " . $name
  528. +                     . " but profiling was not started\n";
  529. +
  530. +                $this->raiseError($msg, null, PEAR_ERROR_DIE);
  531.              }
  532.          }
  533.  
  534.  -391,27 +443,37 @@
  535.              $this->_numberOfCalls[$name] = 1;
  536.          }
  537.  
  538. -        array_push($this->_stack, array("name" => $name, "time" => $this->_getMicrotime()));
  539. +        $data = array("name" => $name, "time" => $this->_getMicrotime());
  540. +        array_push($this->_stack, $data);
  541.      }
  542.  
  543.      /**
  544.       * Leaves code section.
  545.       *
  546. -     * @param  string  name of the marker to be set
  547. -     * @see     stop(), enterSection()
  548. +     * @param string $name The marker to be set
  549. +     *
  550. +     * @see    stop(), enterSection()
  551.       * @access public
  552. +     * @return void
  553.       */
  554. -    function leaveSection($name) {
  555. +    function leaveSection($name)
  556. +    {
  557.          $microtime = $this->_getMicrotime();
  558.  
  559.          if (!count($this->_stack)) {
  560. -            $this->raiseError("tried to leave section ".$name." but profiling was not started\n", NULL, PEAR_ERROR_DIE);
  561. +            $msg = "tried to leave section " . $name
  562. +                 . " but profiling was not started\n";
  563. +
  564. +            $this->raiseError($msg, null, PEAR_ERROR_DIE);
  565.          }
  566.  
  567.          $x = array_pop($this->_stack);
  568.  
  569.          if ($x["name"] != $name) {
  570. -            $this->raiseError("reached end of section $name but expecting end of " . $x["name"]."\n", NULL, PEAR_ERROR_DIE);
  571. +            $msg = "reached end of section " . $name
  572. +                 . " but expecting end of " . $x["name"] . "\n";
  573. +
  574. +            $this->raiseError($msg, null, PEAR_ERROR_DIE);
  575.          }
  576.  
  577.          if (isset($this->_sections[$name])) {
  578.  -422,7 +484,7 @@
  579.  
  580.          $parent = array_pop($this->_stack);
  581.  
  582. -       if (isset($parent)) {
  583. +        if (isset($parent)) {
  584.              if (isset($this->_subSectionsTime[$parent['name']])) {
  585.                  $this->_subSectionsTime[$parent['name']] += $microtime - $x['time'];
  586.              } else {
  587.  -440,7 +502,8 @@
  588.       * @access private
  589.       * @since  1.3.0
  590.       */
  591. -    function _getMicrotime() {
  592. +    function _getMicrotime()
  593. +    {
  594.          $microtime = explode(' ', microtime());
  595.          return $microtime[1] . substr($microtime[0], 1);
  596.      }
  597. Index: Benchmark/Timer.php
  598. ===================================================================
  599. RCS file: /repository/pear/Benchmark/Benchmark/Timer.php,v
  600. retrieving revision 1.2
  601. diff -u -r1.2 Timer.php
  602. --- Benchmark/Timer.php 24 May 2007 05:23:20 -0000      1.2
  603. +++ Benchmark/Timer.php 12 Oct 2008 11:51:24 -0000
  604.  -1,22 +1,27 @@
  605.  <?php
  606. -//
  607. -// +------------------------------------------------------------------------+
  608. -// | PEAR :: Benchmark                                                      |
  609. -// +------------------------------------------------------------------------+
  610. -// | Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  611. -// +------------------------------------------------------------------------+
  612. -// | This source file is subject to the New BSD license, That is bundled    |
  613. -// | with this package in the file LICENSE, and is available through        |
  614. -// | the world-wide-web at                                                  |
  615. -// | http://www.opensource.org/licenses/bsd-license.php                     |
  616. -// | If you did not receive a copy of the new BSDlicense and are unable     |
  617. -// | to obtain it through the world-wide-web, please send a note to         |
  618. -// | license@php.net so we can mail you a copy immediately.                 |
  619. -// +------------------------------------------------------------------------+
  620. -//
  621. -// $Id: Timer.php,v 1.2 2007/05/24 05:23:20 anant Exp $
  622. -//
  623. -
  624. +/**
  625. + * Timer.php                                                      
  626. + *
  627. + * PHP version 4
  628. + *
  629. + * Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>.
  630. + *
  631. + * This source file is subject to the New BSD license, That is bundled    
  632. + * with this package in the file LICENSE, and is available through        
  633. + * the world-wide-web at                                                  
  634. + * http://www.opensource.org/licenses/bsd-license.php                    
  635. + * If you did not receive a copy of the new BSDlicense and are unable    
  636. + * to obtain it through the world-wide-web, please send a note to        
  637. + * license@php.net so we can mail you a copy immediately.                
  638. + *
  639. + * @category  Benchmarking
  640. + * @package   Benchmark
  641. + * @author    Sebastian Bergmann <sb@sebastian-bergmann.de>
  642. + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  643. + * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  644. + * @version   CVS: $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
  645. + * @link      http://pear.php.net/package/Benchmark
  646. + */
  647.  require_once 'PEAR.php';
  648.  
  649.  /**
  650.  -46,18 +51,20 @@
  651.   *
  652.   * $timer->display(); // to output html formated
  653.   * // AND/OR :
  654. - * $profiling = $timer->getProfiling(); // get the profiler info as an associative array
  655. + * $profiling = $timer->getProfiling(); // get profiler info as associative array
  656.   * ?>
  657.   * </code>
  658.   *
  659. + * @category  Benchmarking
  660. + * @package   Benchmark
  661.   * @author    Sebastian Bergmann <sb@sebastian-bergmann.de>
  662.   * @author    Ludovico Magnocavallo <ludo@sumatrasolutions.com>
  663. - * @copyright Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  664. + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  665.   * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  666. - * @category  Benchmarking
  667. - * @package   Benchmark
  668. + * @link      http://pear.php.net/package/Benchmark
  669.   */
  670. -class Benchmark_Timer extends PEAR {
  671. +class Benchmark_Timer extends PEAR
  672. +{
  673.      /**
  674.       * Contains the markers.
  675.       *
  676.  -72,7 +79,7 @@
  677.       * @var    boolean
  678.       * @access private
  679.       */
  680. -    var $auto = FALSE;
  681. +    var $auto = false;
  682.  
  683.      /**
  684.       * Max marker name length for non-html output.
  685.  -85,10 +92,12 @@
  686.      /**
  687.       * Constructor.
  688.       *
  689. -     * @param  boolean $auto
  690. +     * @param boolean $auto Automatically start timer
  691. +     *
  692.       * @access public
  693.       */
  694. -    function Benchmark_Timer($auto = FALSE) {
  695. +    function Benchmark_Timer($auto = false)
  696. +    {
  697.          $this->auto = $auto;
  698.  
  699.          if ($this->auto) {
  700.  -102,8 +111,10 @@
  701.       * Close method. Stop timer and display output.
  702.       *
  703.       * @access public
  704. +     * @return void
  705.       */
  706. -    function close() {
  707. +    function close()
  708. +    {
  709.          if ($this->auto) {
  710.              $this->stop();
  711.              $this->display();
  712.  -115,8 +126,10 @@
  713.       *
  714.       * @see    setMarker(), stop()
  715.       * @access public
  716. +     * @return void
  717.       */
  718. -    function start() {
  719. +    function start()
  720. +    {
  721.          $this->setMarker('Start');
  722.      }
  723.  
  724.  -125,35 +138,42 @@
  725.       *
  726.       * @see    setMarker(), start()
  727.       * @access public
  728. +     * @return void
  729.       */
  730. -    function stop() {
  731. +    function stop()
  732. +    {
  733.          $this->setMarker('Stop');
  734.      }
  735.  
  736.      /**
  737.       * Set marker.
  738.       *
  739. -     * @param  string  $name Name of the marker to be set.
  740. +     * @param string $name Name of the marker to be set.
  741. +     *
  742.       * @see    start(), stop()
  743.       * @access public
  744. +     * @return void
  745.       */
  746. -    function setMarker($name) {
  747. +    function setMarker($name)
  748. +    {
  749.          $this->markers[$name] = $this->_getMicrotime();
  750.      }
  751.  
  752.      /**
  753.       * Returns the time elapsed betweens two markers.
  754.       *
  755. -     * @param  string  $start        start marker, defaults to "Start"
  756. -     * @param  string  $end          end marker, defaults to "Stop"
  757. +     * @param string $start start marker, defaults to "Start"
  758. +     * @param string $end   end marker, defaults to "Stop"
  759. +     *
  760.       * @return double  $time_elapsed time elapsed between $start and $end
  761.       * @access public
  762.       */
  763. -    function timeElapsed($start = 'Start', $end = 'Stop') {
  764. +    function timeElapsed($start = 'Start', $end = 'Stop')
  765. +    {
  766.          if ($end == 'Stop' && !isset($this->markers['Stop'])) {
  767.              $this->markers['Stop'] = $this->_getMicrotime();
  768.          }
  769. -        $end = isset($this->markers[$end]) ? $this->markers[$end] : 0;
  770. +        $end   = isset($this->markers[$end]) ? $this->markers[$end] : 0;
  771.          $start = isset($this->markers[$start]) ? $this->markers[$start] : 0;
  772.  
  773.          if (extension_loaded('bcmath')) {
  774.  -174,10 +194,13 @@
  775.       * @return array
  776.       * @access public
  777.       */
  778. -    function getProfiling() {
  779. +    function getProfiling()
  780. +    {
  781.          $i = $total = 0;
  782. +
  783.          $result = array();
  784. -        $temp = reset($this->markers);
  785. +        $temp   = reset($this->markers);
  786. +
  787.          $this->maxStringLength = 0;
  788.  
  789.          foreach ($this->markers as $marker => $time) {
  790.  -194,15 +217,25 @@
  791.              $result[$i]['diff']  = $diff;
  792.              $result[$i]['total'] = $total;
  793.  
  794. -            $this->maxStringLength = (strlen($marker) > $this->maxStringLength ? strlen($marker) + 1 : $this->maxStringLength);
  795. +            $longer = strlen($marker) > $this->maxStringLength;
  796. +
  797. +            if ($longer) {
  798. +                $this->maxStringLength = strlen($marker) + 1;
  799. +            }
  800.  
  801.              $temp = $time;
  802.              $i++;
  803.          }
  804.  
  805. -        $result[0]['diff'] = '-';
  806. +        $result[0]['diff']  = '-';
  807.          $result[0]['total'] = '-';
  808. -        $this->maxStringLength = (strlen('total') > $this->maxStringLength ? strlen('total') : $this->maxStringLength);
  809. +
  810. +        $longer = strlen('total') > $this->maxStringLength;
  811. +
  812. +        if ($longer) {
  813. +            $this->maxStringLength = strlen('total');
  814. +        }
  815. +
  816.          $this->maxStringLength += 2;
  817.  
  818.          return $result;
  819.  -211,22 +244,25 @@
  820.      /**
  821.       * Return formatted profiling information.
  822.       *
  823. -     * @param  boolean  $showTotal   Optionnaly includes total in output, default no
  824. -     * @param  string  $format   output format (auto, plain or html), default auto
  825. +     * @param boolean $showTotal Optionnaly includes total in output, default no
  826. +     * @param string  $format    output format (auto, plain or html), default auto
  827. +     *
  828.       * @return string
  829.       * @see    getProfiling()
  830.       * @access public
  831.       */
  832. -    function getOutput($showTotal = FALSE, $format = 'auto') {
  833. +    function getOutput($showTotal = false, $format = 'auto')
  834. +    {
  835.          if ($format == 'auto') {
  836.              if (function_exists('version_compare') &&
  837. -                version_compare(phpversion(), '4.1', 'ge'))
  838. -            {
  839. +                version_compare(phpversion(), '4.1', 'ge')) {
  840.                  $format = isset($_SERVER['SERVER_PROTOCOL']) ? 'html' : 'plain';
  841.              } else {
  842.                  global $HTTP_SERVER_VARS;
  843. -                $format = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']) ? 'html' : 'plain';
  844. -           }
  845. +                $use_html = isset($HTTP_SERVER_VARS['SERVER_PROTOCOL']);
  846. +
  847. +                $format = $use_html ? 'html' : 'plain';
  848. +            }
  849.          }
  850.  
  851.          $total  = $this->TimeElapsed();
  852.  -234,14 +270,23 @@
  853.          $dashes = '';
  854.  
  855.          if ($format == 'html') {
  856. -            $out = '<table border="1">'."\n";
  857. -            $out .= '<tr><td>&nbsp;</td><td align="center"><b>time index</b></td><td align="center"><b>ex time</b></td><td align="center"><b>%</b></td>'.
  858. -            ($showTotal ?
  859. -              '<td align="center"><b>elapsed</b></td><td align="center"><b>%</b></td>'
  860. -               : '')."</tr>\n";
  861. +            $out  = '<table border="1">'."\n";
  862. +            $out .= '<tr>';
  863. +            $out .= '<td>&nbsp;</td>';
  864. +            $out .= '<td align="center"><b>time index</b></td>';
  865. +            $out .= '<td align="center"><b>ex time</b></td>';
  866. +            $out .= '<td align="center"><b>%</b></td>';
  867. +
  868. +            if ($showTotal) {
  869. +                 $out .= '<td align="center"><b>elapsed</b></td>';
  870. +                 $out .= '<td align="center"><b>%</b></td>';
  871. +            }
  872. +
  873. +            $out .= "</tr>\n";
  874.          } else {
  875.              $dashes = $out = str_pad("\n",
  876.                  $this->maxStringLength + ($showTotal ? 70 : 45), '-', STR_PAD_LEFT);
  877. +
  878.              $out .= str_pad('marker', $this->maxStringLength) .
  879.                      str_pad("time index", 22) .
  880.                      str_pad("ex time", 16) .
  881.  -251,15 +296,17 @@
  882.          }
  883.  
  884.          foreach ($result as $k => $v) {
  885. -            $perc = (($v['diff'] * 100) / $total);
  886. +            $perc  = (($v['diff'] * 100) / $total);
  887.              $tperc = (($v['total'] * 100) / $total);
  888.  
  889. +            $percentage = number_format($perc, 2, '.', '')."%";
  890. +
  891.              if ($format == 'html') {
  892.                  $out .= "<tr><td><b>" . $v['name'] .
  893.                         "</b></td><td>" . $v['time'] .
  894.                         "</td><td>" . $v['diff'] .
  895. -                       "</td><td align=\"right\">" . number_format($perc, 2, '.', '') .
  896. -                       "%</td>".
  897. +                       "</td><td align=\"right\">" . $percentage .
  898. +                       "</td>".
  899.                         ($showTotal ?
  900.                              "<td>" . $v['total'] .
  901.                              "</td><td align=\"right\">" .
  902.  -267,10 +314,12 @@
  903.                              "%</td>" : '').
  904.                         "</tr>\n";
  905.              } else {
  906. +
  907. +
  908.                  $out .= str_pad($v['name'], $this->maxStringLength, ' ') .
  909.                          str_pad($v['time'], 22) .
  910.                          str_pad($v['diff'], 14) .
  911. -                        str_pad(number_format($perc, 2, '.', '')."%",8, ' ', STR_PAD_LEFT) .
  912. +                        str_pad($percentage, 8, ' ', STR_PAD_LEFT) .
  913.                          ($showTotal ? '   '.
  914.                              str_pad($v['total'], 14) .
  915.                              str_pad(number_format($tperc, 2, '.', '')."%",
  916.  -282,7 +331,13 @@
  917.          }
  918.  
  919.          if ($format == 'html') {
  920. -            $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";
  921. +            $out .= "<tr style='background: silver;'>";
  922. +            $out .= "<td><b>total</b></td>";
  923. +            $out .= "<td>-</td>";
  924. +            $out .= "<td>${total}</td>";
  925. +            $out .= "<td>100.00%</td>";
  926. +            $out .= ($showTotal ? "<td>-</td><td>-</td>" : "");
  927. +            $out .= "</tr>\n";
  928.              $out .= "</table>\n";
  929.          } else {
  930.              $out .= str_pad('total', $this->maxStringLength);
  931.  -298,12 +353,15 @@
  932.      /**
  933.       * Prints the information returned by getOutput().
  934.       *
  935. -     * @param  boolean  $showTotal   Optionnaly includes total in output, default no
  936. -     * @param  string  $format   output format (auto, plain or html), default auto
  937. +     * @param boolean $showTotal Optionnaly includes total in output, default no
  938. +     * @param string  $format    output format (auto, plain or html), default auto
  939. +     *
  940.       * @see    getOutput()
  941.       * @access public
  942. +     * @return void
  943.       */
  944. -    function display($showTotal = FALSE, $format = 'auto') {
  945. +    function display($showTotal = false, $format = 'auto')
  946. +    {
  947.          print $this->getOutput($showTotal, $format);
  948.      }
  949.  
  950.  -314,7 +372,8 @@
  951.       * @access private
  952.       * @since  1.3.0
  953.       */
  954. -    function _getMicrotime() {
  955. +    function _getMicrotime()
  956. +    {
  957.          $microtime = explode(' ', microtime());
  958.          return $microtime[1] . substr($microtime[0], 1);
  959.      }
  960. Index: doc/timer_example.php
  961. ===================================================================
  962. RCS file: /repository/pear/Benchmark/doc/timer_example.php,v
  963. retrieving revision 1.4
  964. diff -u -r1.4 timer_example.php
  965. --- doc/timer_example.php       14 Apr 2006 14:10:43 -0000      1.4
  966. +++ doc/timer_example.php       12 Oct 2008 11:51:25 -0000
  967.  -1,11 +1,45 @@
  968.  <?php
  969. +/**
  970. + * timer_example.php
  971. + *
  972. + * PHP version 4
  973. + *
  974. + * Copyright (c) 2001-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>.
  975. + *
  976. + * This source file is subject to the New BSD license, That is bundled    
  977. + * with this package in the file LICENSE, and is available through        
  978. + * the world-wide-web at                                                  
  979. + * http://www.opensource.org/licenses/bsd-license.php                    
  980. + * If you did not receive a copy of the new BSDlicense and are unable    
  981. + * to obtain it through the world-wide-web, please send a note to        
  982. + * license@php.net so we can mail you a copy immediately.                
  983. + *
  984. + * @category  Benchmarking
  985. + * @package   Benchmark
  986. + * @author    Sebastian Bergmann <sb@sebastian-bergmann.de>
  987. + * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  988. + * @license   http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  989. + * @version   CVS: $Id: Iterate.php,v 1.1 2007/05/24 05:17:56 anant Exp $
  990. + * @link      http://pear.php.net/package/Benchmark
  991. + */
  992. +
  993.  require 'Benchmark/Timer.php';
  994.  
  995. -function wait($amount) {
  996. +/**
  997. + * Wait
  998. + *
  999. + * @param int $amount Amount to wait
  1000. + *
  1001. + * @return void
  1002. + */
  1003. +function wait($amount)
  1004. +{
  1005.      for ($i=0; $i < $amount; $i++) {
  1006. -        for ($i=0; $i < 100; $i++);
  1007. +        for ($i=0; $i < 100; $i++) {
  1008. +        }
  1009.      }
  1010.  }
  1011. +
  1012.  // Pass the param "true" to constructor to automatically display the results
  1013.  $timer = new Benchmark_Timer();
  1014.  $timer->start();