cvs: php4 /pear Log.php Makefile.in /pear/Benchmark Iterate.php Timer.php /pear/Log Observer.php composite.php file.php mcal.php sql.php syslog.php
/pear/Math Fraction.php Util.php /pear/Numbers Roman.php pear/Benchmark Iterate.php Timer.php package.xml pear/Math Fraction.php Util.php
package.xml pear/Math_Numbers Roman.php package.xml
| From: | Sebastian Bergmann | Date: | Sun, 20 Jan 2002 15:44:37 +0000 |
| Subject: | cvs: php4 /pear Log.php Makefile.in /pear/Benchmark Iterate.php Timer.php /pear/Log Observer.php composite.php file.php mcal.php sql.php syslog.php /pear/Math Fraction.php Util.php /pear/Numbers Roman.php pear/Benchmark Iterate.php Timer.php package.xml pear/Math Fraction.php Util.php package.xml pear/Math_Numbers Roman.php package.xml |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-2016@lists.php.net to get a copy of this message | ||
sebastian Sun Jan 20 10:44:37 2002 EDT
Added files:
/pear/Benchmark Iterate.php Timer.php package.xml
/pear/Math Fraction.php Util.php package.xml
/pear/Math_Numbers Roman.php package.xml
Removed files:
/php4/pear Log.php
/php4/pear/Benchmark Iterate.php Timer.php
/php4/pear/Log Observer.php composite.php file.php mcal.php sql.php
syslog.php
/php4/pear/Math Fraction.php Util.php
/php4/pear/Numbers Roman.php
Modified files:
/php4/pear Makefile.in
Log:
Move Benchmark, Math, Numbers to /pear. Remove Log, it was already in /pear.
Index: php4/pear/Makefile.in diff -u php4/pear/Makefile.in:1.97 php4/pear/Makefile.in:1.98 --- php4/pear/Makefile.in:1.97 Wed Jan 2 12:11:34 2002 +++ php4/pear/Makefile.in Sun Jan 20 10:44:32 2002 @@ -10,7 +10,6 @@ peardir=$(PEAR_INSTALLDIR) PEAR_SUBDIRS = \ - Benchmark \ Cache \ Cache/Container \ Console \ @@ -21,19 +20,14 @@ HTML \ HTTP \ Image \ - Log \ Mail \ - Math \ Net \ - Numbers \ Payment \ PEAR \ Schedule \ XML PEAR_FILES = \ - Benchmark/Iterate.php \ - Benchmark/Timer.php \ Cache.php \ Cache/Error.php \ Cache/Container.php \ @@ -80,25 +74,15 @@ HTTP.php \ HTTP/Compress.php \ Image/Remote.php \ - Log.php \ - Log/composite.php \ - Log/file.php \ - Log/mcal.php \ - Log/Observer.php \ - Log/sql.php \ - Log/syslog.php \ Mail.php \ Mail/RFC822.php \ Mail/sendmail.php \ Mail/smtp.php \ Mail/mime.php \ - Math/Fraction.php \ - Math/Util.php \ Net/Curl.php \ Net/Dig.php \ Net/SMTP.php \ Net/Socket.php \ - Numbers/Roman.php \ PEAR.php \ PEAR/Autoloader.php \ PEAR/Common.php \ Index: pear/Benchmark/Iterate.php +++ pear/Benchmark/Iterate.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: Iterate.php,v 1.1 2002/01/20 15:44:31 sebastian Exp $ // require_once 'Benchmark/Timer.php'; /** * Benchmark::Benchmark_Iterate * * Purpose: * * Benchmarking * * Example: * a) * require_once 'Benchmark/Iterate.php'; * $benchmark = new Benchmark_Iterate; * * function foo($string) { * print $string . '<br>'; * } * * $benchmark->run(100, 'foo', 'test'); * $result = $benchmark->get(); * * b) * require_once 'Benchmark/Iterate.php'; * $benchmark = new Benchmark_Iterate; * * class myclass{ * * function foo($string) { * print $string . '<br>'; * } * } * * $benchmark->run(100, 'myclass::foo', 'test'); * $result = $benchmark->get(); * * c) * require_once 'Benchmark/Iterate.php'; * $benchmark = new Benchmark_Iterate; * * class myclass{ * * function foo($string) { * print $string . '<br>'; * } * } * * $myobj = new myclass(); * * $benchmark->run(100, 'myobj->foo', 'test'); * $result = $benchmark->get(); * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @access public */ class Benchmark_Iterate extends Benchmark_Timer { /** * Benchmarks a function. * * @access public */ 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]; } // If we're calling a method on an object use call_user_method if (strstr($function_name, '->')) { $function_name = explode('->', $function_name); $objectname = $function_name[0]; global ${$objectname}; $objectmethod = $function_name[1]; for ($i = 1; $i <= $iterations; $i++) { $this->setMarker('start_' . $i); call_user_method_array($function_name[1], ${$objectname}, $arguments); $this->setMarker('end_' . $i); } return(0); } for ($i = 1; $i <= $iterations; $i++) { $this->setMarker('start_' . $i); call_user_func_array($function_name, $arguments); $this->setMarker('end_' . $i); } } /** * Returns benchmark result. * * $result[x ] = execution time of iteration x * $result['mean' ] = mean execution time * $result['iterations'] = number of iterations * * @return array $result * @access public */ function get() { $result = array(); $total = 0; $iterations = count($this->markers)/2; for ($i = 1; $i <= $iterations; $i++) { $time = $this->timeElapsed('start_'.$i , 'end_'.$i); if (extension_loaded('bcmath')) { $total = bcadd($total, $time, 6); } else { $total = $total + $time; } $result[$i] = $time; } if (extension_loaded('bcmath')) { $result['mean'] = bcdiv($total, $iterations, 6); } else { $result['mean'] = $total / $iterations; } $result['iterations'] = $iterations; return $result; } } ?> Index: pear/Benchmark/Timer.php +++ pear/Benchmark/Timer.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: Timer.php,v 1.1 2002/01/20 15:44:31 sebastian Exp $ // /** * Benchmark::Timer * * Purpose: * * Timing Script Execution, Generating Profiling Information * * Example: * * $timer = new Benchmark_Timer; * * $timer->start(); * $timer->setMarker('Marker 1'); * $timer->stop(); * * $profiling = $timer->getProfiling(); * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @access public */ class Benchmark_Timer { /** * Contains the markers * * @var array * @access public */ var $markers = array(); /** * Set "Start" marker. * * @see setMarker(), stop() * @access public */ function start() { $this->setMarker('Start'); } /** * Set "Stop" marker. * * @see setMarker(), start() * @access public */ function stop() { $this->setMarker('Stop'); } /** * Set marker. * * @param string name of the marker to be set * @see start(), stop() * @access public */ function setMarker($name) { $microtime = explode(' ', microtime()); $this->markers[$name] = $microtime[1] . substr($microtime[0], 1); } /** * Returns the time elapsed betweens two markers. * * @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') { if (extension_loaded('bcmath')) { return bcsub($this->markers[$end], $this->markers[$start], 6); } else { return $this->markers[$end] - $this->markers[$start]; } } /** * Returns profiling information. * * $profiling[x]['name'] = name of marker x * $profiling[x]['time'] = time index of marker x * $profiling[x]['diff'] = execution time from marker x-1 to this marker x * $profiling[x]['total'] = total execution time up to marker x * * @return array $profiling * @access public */ function getProfiling() { $i = 0; $total = 0; $result = array(); foreach ($this->markers as $marker => $time) { if ($marker == 'Start') { $diff = '-'; } else { if (extension_loaded('bcmath')) { $diff = bcsub($time, $temp, 6); $total = bcadd($total, $diff, 6); } else { $diff = $time - $temp; $total = $total + $diff; } } $result[$i]['name'] = $marker; $result[$i]['time'] = $time; $result[$i]['diff'] = $diff; $result[$i]['total'] = $total; $temp = $time; $i++; } return $result; } } ?> Index: pear/Benchmark/package.xml +++ pear/Benchmark/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package> <name>Benchmark</name> <summary>Framework to benchmark PHP scripts or function calls.</summary> <description> Framework to benchmark PHP scripts or function calls. </description> <maintainer> <user>sebastian</user> <name>Sebastian Bergmann</name> <email>sb@sebastian-bergmann.de</email> </maintainer> <release> <version>1.0</version> <date>2002-01-20</date> <notes> This is the initial independent PEAR release. </notes> </release> <filelist> <dir name="/"> <file role="php">Timer.php</file> <file role="php">Iterate.php</file> </dir> </filelist> </package> Index: pear/Math/Fraction.php +++ pear/Math/Fraction.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: Fraction.php,v 1.1 2002/01/20 15:44:32 sebastian Exp $ // /** * Math::Math_Fraction * * Purpose: * * Class for handling fractions. * * Example: * * $a = new Math_Fraction( 1, 2 ); * $b = new Math_Fraction( 3, 4 ); * * $a->add( $b ); * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @access public * @package Numbers */ require_once 'Math/Util.php'; class Math_Fraction { /** * numerator of the fraction * * @var int numerator * @access public */ var $numerator; /** * denominator of the fraction * * @var int denominator * @access public */ var $denominator; /** * Constructor * * @param int numerator * @param int denominator * @access public */ function Math_Fraction($numerator, $denominator = 1) { $this->numerator = $numerator; $this->denominator = $denominator; } /** * Add another fraction to this one. * * @param Math_Fraction fraction * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access public * @see sub, mul, div */ function add($fraction, $overwrite_with_result = true) { $fraction = $this->_check_fraction($fraction); $result = new Math_Fraction((($this->numerator * $fraction->denominator) + ($this->denominator * $fraction->numerator)), ($this->denominator * $fraction->denominator) ); return $this->_return($result, $overwrite_with_result); } /** * Subtract another fraction from this one. * * @param Math_Fraction fraction * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access public * @see add, mul, div */ function sub($fraction, $overwrite_with_result = true) { $fraction = $this->_check_fraction($fraction); $result = new Math_Fraction((($this->numerator * $fraction->denominator) - ($this->denominator * $fraction->numerator)), ($this->denominator * $fraction->denominator) ); return $this->_return($result, $overwrite_with_result); } /** * Multiply another fraction with this one. * * @param Math_Fraction fraction * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access public * @see add, sub, div */ function mul($fraction, $overwrite_with_result = true) { $fraction = $this->_check_fraction( $fraction ); $result = new Math_Fraction(($this->numerator * $fraction->numerator), ($this->denominator * $fraction->denominator) ); return $this->_return($result, $overwrite_with_result); } /** * Divide this fraction by another one. * * @param Math_Fraction fraction * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access public * @see add, sub, mul */ function div($fraction, $overwrite_with_result = true) { $fraction = $this->_check_fraction( $fraction ); $result = new Math_Fraction(($this->numerator * $fraction->denominator), ($this->denominator * $fraction->numerator) ); return $this->_return($result, $overwrite_with_result); } /** * Normalize this fraction. * * @access public */ function normalize() { $gcd = Math_Util::gcd($this->numerator, $this->denominator); $this->numerator = $this->numerator / $gcd; $this->denominator = $this->denominator / $gcd; } /** * Dump this fraction. * * @access public */ function dump() { echo $this->get(); } /** * Get string representation of this fraction. * * @return string representation of fraction * @access public */ function get() { return $this->numerator . ' / ' . $this->denominator; } /** * Check, if a varaible holds a Math_Fraction object. * * @param Math_Fraction fraction to be checked * @return Math_Fraction checked fraction * @access private */ function _check_fraction($fraction) { if (get_class($fraction) != 'math_fraction') { $fraction = new Math_Fraction( $fraction ); } return $fraction; } /** * Handle the return or storage of a result from add, sub, mul or div. * * @param Math_Fraction result * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access private */ function _return($result, $overwrite_with_result) { $result->normalize(); if ($overwrite_with_result) { $this->numerator = $result->numerator; $this->denominator = $result->denominator; } else { return $result; } } } ?> Index: pear/Math/Util.php +++ pear/Math/Util.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: Util.php,v 1.1 2002/01/20 15:44:35 sebastian Exp $ // /** * Mathematic utilities * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @package Numbers */ class Math_Util { /** * Calculates the Greatest Common Divisor (gcd) of two numbers. * * @param int a first number * @param int b second number * @return int gcd(a,b) * @access public */ function gcd($a, $b) { if ($b > $a) { list($a, $b) = array($b, $a); } $c = 1; // the magic loop (thanks, Euclid :-) while ($c > 0) { $c = $a % $b; $a = $b; $b = $c; } return $a; } } ?> Index: pear/Math/package.xml +++ pear/Math/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package> <name>Math</name> <summary>Mathematical library.</summary> <description> Mathematical library. </description> <maintainer> <user>sebastian</user> <name>Sebastian Bergmann</name> <email>sb@sebastian-bergmann.de</email> </maintainer> <release> <version>1.0</version> <date>2002-01-20</date> <notes> This is the initial independent PEAR release. </notes> </release> <filelist> <dir name="/"> <file role="php">Fraction.php</file> <file role="php">Util.php</file> </dir> </filelist> </package> Index: pear/Math_Numbers/Roman.php +++ pear/Math_Numbers/Roman.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // require_once("PEAR.php"); // {{{ Numbers_Roman /** * The Numbers_Roman class provides utilities to convert roman numerals to * arabic numbers and convert arabic numbers to roman numerals * * @access public * @author Sterling Hughes <sterling@php.net> * @since PHP 4.0.5 */ class Numbers_Roman extends PEAR { // {{{ toNumber() /** * Converts a roman numeral to a number * * @param string $roman The roman numeral to convert * * @return integer $num The number corresponding to the * given roman numeral * * @access public * @author Sterling Hughes <sterling@php.net> * @since PHP 4.0.5 */ function toNumber($roman) { $conv = array( array("letter" => 'I', "number" => 1), array("letter" => 'V', "number" => 5), array("letter" => 'X', "number" => 10), array("letter" => 'L', "number" => 50), array("letter" => 'C', "number" => 100), array("letter" => 'D', "number" => 500), array("letter" => 'M', "number" => 1000), array("letter" => 0, "number" => 0) ); $arabic = 0; $state = 0; $sidx = 0; $len = strlen($roman) - 1; while ($len >= 0) { $i = 0; $sidx = $len; while ($conv[$i]['number'] > 0) { if (strtoupper($roman[$sidx]) == $conv[$i]['letter']) { if ($state > $conv[$i]['number']) { $arabic -= $conv[$i]['number']; } else { $arabic += $conv[$i]['number']; $state = $conv[$i]['number']; } } $i++; } $len--; } return($arabic); } // }}} // {{{ toRoman() /** * Converts a number to its roman numeral representation * * @param integer $num An integer between 0 and 3999 inclusive * that should be converted to a roman numeral * * @return string $roman The corresponding roman numeral * * @access public * @author Sterling Hughes <sterling@php.net> * @since PHP 4.0.5 */ function toRoman($num) { $conv = array(10 => array('X', 'C', 'M'), 5 => array('V', 'L', 'D'), 1 => array('I', 'X', 'C')); $roman = ''; if ($num < 0) { return ''; } $num = (int) $num; $digit = (int) ($num / 1000); $num -= $digit * 1000; while ($digit > 0) { $roman .= 'M'; $digit--; } for ($i = 2; $i >= 0; $i--) { $power = pow(10, $i); $digit = (int) ($num / $power); $num -= $digit * $power; if (($digit == 9) || ($digit == 4)) { $roman .= $conv[1][$i] . $conv[$digit+1][$i]; } else { if ($digit >= 5) { $roman .= $conv[5][$i]; $digit -= 5; } while ($digit > 0) { $roman .= $conv[1][$i]; $digit--; } } } return $roman; } // }}} } // }}} ?> Index: pear/Math_Numbers/package.xml +++ pear/Math_Numbers/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package> <name>Math_Number</name> <summary>Library to work with different number formats.</summary> <description> Library to work with different number formats. </description> <maintainer> <user>sterling</user> <name>Sterling Hughes</name> <email>sterling@php.net</email> </maintainer> <release> <version>1.0</version> <date>2002-01-20</date> <notes> This is the initial independent PEAR release. </notes> </release> <filelist> <dir name="/" baseinstalldir="Math"> <file role="php">Roman.php</file> </dir> </filelist> </package>
Index: php4/pear/Makefile.in diff -u php4/pear/Makefile.in:1.97 php4/pear/Makefile.in:1.98 --- php4/pear/Makefile.in:1.97 Wed Jan 2 12:11:34 2002 +++ php4/pear/Makefile.in Sun Jan 20 10:44:32 2002 @@ -10,7 +10,6 @@ peardir=$(PEAR_INSTALLDIR) PEAR_SUBDIRS = \ - Benchmark \ Cache \ Cache/Container \ Console \ @@ -21,19 +20,14 @@ HTML \ HTTP \ Image \ - Log \ Mail \ - Math \ Net \ - Numbers \ Payment \ PEAR \ Schedule \ XML PEAR_FILES = \ - Benchmark/Iterate.php \ - Benchmark/Timer.php \ Cache.php \ Cache/Error.php \ Cache/Container.php \ @@ -80,25 +74,15 @@ HTTP.php \ HTTP/Compress.php \ Image/Remote.php \ - Log.php \ - Log/composite.php \ - Log/file.php \ - Log/mcal.php \ - Log/Observer.php \ - Log/sql.php \ - Log/syslog.php \ Mail.php \ Mail/RFC822.php \ Mail/sendmail.php \ Mail/smtp.php \ Mail/mime.php \ - Math/Fraction.php \ - Math/Util.php \ Net/Curl.php \ Net/Dig.php \ Net/SMTP.php \ Net/Socket.php \ - Numbers/Roman.php \ PEAR.php \ PEAR/Autoloader.php \ PEAR/Common.php \ Index: pear/Benchmark/Iterate.php +++ pear/Benchmark/Iterate.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: Iterate.php,v 1.1 2002/01/20 15:44:31 sebastian Exp $ // require_once 'Benchmark/Timer.php'; /** * Benchmark::Benchmark_Iterate * * Purpose: * * Benchmarking * * Example: * a) * require_once 'Benchmark/Iterate.php'; * $benchmark = new Benchmark_Iterate; * * function foo($string) { * print $string . '<br>'; * } * * $benchmark->run(100, 'foo', 'test'); * $result = $benchmark->get(); * * b) * require_once 'Benchmark/Iterate.php'; * $benchmark = new Benchmark_Iterate; * * class myclass{ * * function foo($string) { * print $string . '<br>'; * } * } * * $benchmark->run(100, 'myclass::foo', 'test'); * $result = $benchmark->get(); * * c) * require_once 'Benchmark/Iterate.php'; * $benchmark = new Benchmark_Iterate; * * class myclass{ * * function foo($string) { * print $string . '<br>'; * } * } * * $myobj = new myclass(); * * $benchmark->run(100, 'myobj->foo', 'test'); * $result = $benchmark->get(); * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @access public */ class Benchmark_Iterate extends Benchmark_Timer { /** * Benchmarks a function. * * @access public */ 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]; } // If we're calling a method on an object use call_user_method if (strstr($function_name, '->')) { $function_name = explode('->', $function_name); $objectname = $function_name[0]; global ${$objectname}; $objectmethod = $function_name[1]; for ($i = 1; $i <= $iterations; $i++) { $this->setMarker('start_' . $i); call_user_method_array($function_name[1], ${$objectname}, $arguments); $this->setMarker('end_' . $i); } return(0); } for ($i = 1; $i <= $iterations; $i++) { $this->setMarker('start_' . $i); call_user_func_array($function_name, $arguments); $this->setMarker('end_' . $i); } } /** * Returns benchmark result. * * $result[x ] = execution time of iteration x * $result['mean' ] = mean execution time * $result['iterations'] = number of iterations * * @return array $result * @access public */ function get() { $result = array(); $total = 0; $iterations = count($this->markers)/2; for ($i = 1; $i <= $iterations; $i++) { $time = $this->timeElapsed('start_'.$i , 'end_'.$i); if (extension_loaded('bcmath')) { $total = bcadd($total, $time, 6); } else { $total = $total + $time; } $result[$i] = $time; } if (extension_loaded('bcmath')) { $result['mean'] = bcdiv($total, $iterations, 6); } else { $result['mean'] = $total / $iterations; } $result['iterations'] = $iterations; return $result; } } ?> Index: pear/Benchmark/Timer.php +++ pear/Benchmark/Timer.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: Timer.php,v 1.1 2002/01/20 15:44:31 sebastian Exp $ // /** * Benchmark::Timer * * Purpose: * * Timing Script Execution, Generating Profiling Information * * Example: * * $timer = new Benchmark_Timer; * * $timer->start(); * $timer->setMarker('Marker 1'); * $timer->stop(); * * $profiling = $timer->getProfiling(); * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @access public */ class Benchmark_Timer { /** * Contains the markers * * @var array * @access public */ var $markers = array(); /** * Set "Start" marker. * * @see setMarker(), stop() * @access public */ function start() { $this->setMarker('Start'); } /** * Set "Stop" marker. * * @see setMarker(), start() * @access public */ function stop() { $this->setMarker('Stop'); } /** * Set marker. * * @param string name of the marker to be set * @see start(), stop() * @access public */ function setMarker($name) { $microtime = explode(' ', microtime()); $this->markers[$name] = $microtime[1] . substr($microtime[0], 1); } /** * Returns the time elapsed betweens two markers. * * @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') { if (extension_loaded('bcmath')) { return bcsub($this->markers[$end], $this->markers[$start], 6); } else { return $this->markers[$end] - $this->markers[$start]; } } /** * Returns profiling information. * * $profiling[x]['name'] = name of marker x * $profiling[x]['time'] = time index of marker x * $profiling[x]['diff'] = execution time from marker x-1 to this marker x * $profiling[x]['total'] = total execution time up to marker x * * @return array $profiling * @access public */ function getProfiling() { $i = 0; $total = 0; $result = array(); foreach ($this->markers as $marker => $time) { if ($marker == 'Start') { $diff = '-'; } else { if (extension_loaded('bcmath')) { $diff = bcsub($time, $temp, 6); $total = bcadd($total, $diff, 6); } else { $diff = $time - $temp; $total = $total + $diff; } } $result[$i]['name'] = $marker; $result[$i]['time'] = $time; $result[$i]['diff'] = $diff; $result[$i]['total'] = $total; $temp = $time; $i++; } return $result; } } ?> Index: pear/Benchmark/package.xml +++ pear/Benchmark/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package> <name>Benchmark</name> <summary>Framework to benchmark PHP scripts or function calls.</summary> <description> Framework to benchmark PHP scripts or function calls. </description> <maintainer> <user>sebastian</user> <name>Sebastian Bergmann</name> <email>sb@sebastian-bergmann.de</email> </maintainer> <release> <version>1.0</version> <date>2002-01-20</date> <notes> This is the initial independent PEAR release. </notes> </release> <filelist> <dir name="/"> <file role="php">Timer.php</file> <file role="php">Iterate.php</file> </dir> </filelist> </package> Index: pear/Math/Fraction.php +++ pear/Math/Fraction.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: Fraction.php,v 1.1 2002/01/20 15:44:32 sebastian Exp $ // /** * Math::Math_Fraction * * Purpose: * * Class for handling fractions. * * Example: * * $a = new Math_Fraction( 1, 2 ); * $b = new Math_Fraction( 3, 4 ); * * $a->add( $b ); * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @access public * @package Numbers */ require_once 'Math/Util.php'; class Math_Fraction { /** * numerator of the fraction * * @var int numerator * @access public */ var $numerator; /** * denominator of the fraction * * @var int denominator * @access public */ var $denominator; /** * Constructor * * @param int numerator * @param int denominator * @access public */ function Math_Fraction($numerator, $denominator = 1) { $this->numerator = $numerator; $this->denominator = $denominator; } /** * Add another fraction to this one. * * @param Math_Fraction fraction * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access public * @see sub, mul, div */ function add($fraction, $overwrite_with_result = true) { $fraction = $this->_check_fraction($fraction); $result = new Math_Fraction((($this->numerator * $fraction->denominator) + ($this->denominator * $fraction->numerator)), ($this->denominator * $fraction->denominator) ); return $this->_return($result, $overwrite_with_result); } /** * Subtract another fraction from this one. * * @param Math_Fraction fraction * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access public * @see add, mul, div */ function sub($fraction, $overwrite_with_result = true) { $fraction = $this->_check_fraction($fraction); $result = new Math_Fraction((($this->numerator * $fraction->denominator) - ($this->denominator * $fraction->numerator)), ($this->denominator * $fraction->denominator) ); return $this->_return($result, $overwrite_with_result); } /** * Multiply another fraction with this one. * * @param Math_Fraction fraction * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access public * @see add, sub, div */ function mul($fraction, $overwrite_with_result = true) { $fraction = $this->_check_fraction( $fraction ); $result = new Math_Fraction(($this->numerator * $fraction->numerator), ($this->denominator * $fraction->denominator) ); return $this->_return($result, $overwrite_with_result); } /** * Divide this fraction by another one. * * @param Math_Fraction fraction * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access public * @see add, sub, mul */ function div($fraction, $overwrite_with_result = true) { $fraction = $this->_check_fraction( $fraction ); $result = new Math_Fraction(($this->numerator * $fraction->denominator), ($this->denominator * $fraction->numerator) ); return $this->_return($result, $overwrite_with_result); } /** * Normalize this fraction. * * @access public */ function normalize() { $gcd = Math_Util::gcd($this->numerator, $this->denominator); $this->numerator = $this->numerator / $gcd; $this->denominator = $this->denominator / $gcd; } /** * Dump this fraction. * * @access public */ function dump() { echo $this->get(); } /** * Get string representation of this fraction. * * @return string representation of fraction * @access public */ function get() { return $this->numerator . ' / ' . $this->denominator; } /** * Check, if a varaible holds a Math_Fraction object. * * @param Math_Fraction fraction to be checked * @return Math_Fraction checked fraction * @access private */ function _check_fraction($fraction) { if (get_class($fraction) != 'math_fraction') { $fraction = new Math_Fraction( $fraction ); } return $fraction; } /** * Handle the return or storage of a result from add, sub, mul or div. * * @param Math_Fraction result * @param boolean overwrite_with_result * @return Math_Fraction result (if overwrite_with_result == false) * @access private */ function _return($result, $overwrite_with_result) { $result->normalize(); if ($overwrite_with_result) { $this->numerator = $result->numerator; $this->denominator = $result->denominator; } else { return $result; } } } ?> Index: pear/Math/Util.php +++ pear/Math/Util.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // // $Id: Util.php,v 1.1 2002/01/20 15:44:35 sebastian Exp $ // /** * Mathematic utilities * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @version $Revision: 1.1 $ * @package Numbers */ class Math_Util { /** * Calculates the Greatest Common Divisor (gcd) of two numbers. * * @param int a first number * @param int b second number * @return int gcd(a,b) * @access public */ function gcd($a, $b) { if ($b > $a) { list($a, $b) = array($b, $a); } $c = 1; // the magic loop (thanks, Euclid :-) while ($c > 0) { $c = $a % $b; $a = $b; $b = $c; } return $a; } } ?> Index: pear/Math/package.xml +++ pear/Math/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package> <name>Math</name> <summary>Mathematical library.</summary> <description> Mathematical library. </description> <maintainer> <user>sebastian</user> <name>Sebastian Bergmann</name> <email>sb@sebastian-bergmann.de</email> </maintainer> <release> <version>1.0</version> <date>2002-01-20</date> <notes> This is the initial independent PEAR release. </notes> </release> <filelist> <dir name="/"> <file role="php">Fraction.php</file> <file role="php">Util.php</file> </dir> </filelist> </package> Index: pear/Math_Numbers/Roman.php +++ pear/Math_Numbers/Roman.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license 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. | // +----------------------------------------------------------------------+ // | Authors: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // require_once("PEAR.php"); // {{{ Numbers_Roman /** * The Numbers_Roman class provides utilities to convert roman numerals to * arabic numbers and convert arabic numbers to roman numerals * * @access public * @author Sterling Hughes <sterling@php.net> * @since PHP 4.0.5 */ class Numbers_Roman extends PEAR { // {{{ toNumber() /** * Converts a roman numeral to a number * * @param string $roman The roman numeral to convert * * @return integer $num The number corresponding to the * given roman numeral * * @access public * @author Sterling Hughes <sterling@php.net> * @since PHP 4.0.5 */ function toNumber($roman) { $conv = array( array("letter" => 'I', "number" => 1), array("letter" => 'V', "number" => 5), array("letter" => 'X', "number" => 10), array("letter" => 'L', "number" => 50), array("letter" => 'C', "number" => 100), array("letter" => 'D', "number" => 500), array("letter" => 'M', "number" => 1000), array("letter" => 0, "number" => 0) ); $arabic = 0; $state = 0; $sidx = 0; $len = strlen($roman) - 1; while ($len >= 0) { $i = 0; $sidx = $len; while ($conv[$i]['number'] > 0) { if (strtoupper($roman[$sidx]) == $conv[$i]['letter']) { if ($state > $conv[$i]['number']) { $arabic -= $conv[$i]['number']; } else { $arabic += $conv[$i]['number']; $state = $conv[$i]['number']; } } $i++; } $len--; } return($arabic); } // }}} // {{{ toRoman() /** * Converts a number to its roman numeral representation * * @param integer $num An integer between 0 and 3999 inclusive * that should be converted to a roman numeral * * @return string $roman The corresponding roman numeral * * @access public * @author Sterling Hughes <sterling@php.net> * @since PHP 4.0.5 */ function toRoman($num) { $conv = array(10 => array('X', 'C', 'M'), 5 => array('V', 'L', 'D'), 1 => array('I', 'X', 'C')); $roman = ''; if ($num < 0) { return ''; } $num = (int) $num; $digit = (int) ($num / 1000); $num -= $digit * 1000; while ($digit > 0) { $roman .= 'M'; $digit--; } for ($i = 2; $i >= 0; $i--) { $power = pow(10, $i); $digit = (int) ($num / $power); $num -= $digit * $power; if (($digit == 9) || ($digit == 4)) { $roman .= $conv[1][$i] . $conv[$digit+1][$i]; } else { if ($digit >= 5) { $roman .= $conv[5][$i]; $digit -= 5; } while ($digit > 0) { $roman .= $conv[1][$i]; $digit--; } } } return $roman; } // }}} } // }}} ?> Index: pear/Math_Numbers/package.xml +++ pear/Math_Numbers/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package> <name>Math_Number</name> <summary>Library to work with different number formats.</summary> <description> Library to work with different number formats. </description> <maintainer> <user>sterling</user> <name>Sterling Hughes</name> <email>sterling@php.net</email> </maintainer> <release> <version>1.0</version> <date>2002-01-20</date> <notes> This is the initial independent PEAR release. </notes> </release> <filelist> <dir name="/" baseinstalldir="Math"> <file role="php">Roman.php</file> </dir> </filelist> </package>