Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('COUNT', 1000);
- $tests = array('<b>PHP native</b>', '<b>PHP eval</b>', '<b>PEAR RPN true-rpn</b>', '<b>PEAR RPN generic</b>');
- $results = array();
- echo "<p>Running ".COUNT." times</p>";
- echo "<p>Using $tests[0]: ";
- $start = microtime(true);
- for($i=0; $i<COUNT; $i++) {
- $ret = 1230 + 1800 + $i;
- }
- $results[0] = microtime(true) - $start;
- echo $results[0]; echo 's</p>';
- echo "<p>Using $tests[1]: ";
- $start = microtime(true);
- for($i=0; $i<COUNT; $i++) {
- if (!($ret = eval('return 1230 + 1800 + '.$i.';'))) {
- die('error in eval expression');
- } else {
- //print $ret . '<br/>';
- }
- }
- $results[1] = microtime(true) - $start;
- echo $results[1]; echo 's</p>';
- echo "<p>Using $tests[2]: ";
- $start = microtime(true);
- include_once 'Math/RPN.php';
- $rpn = new Math_Rpn();
- for($i=0; $i<COUNT; $i++) {
- $expression = '1230 1800 + '.$i.' +';
- if (($ret = $rpn->calculate($expression, 'deg', true)) == 'Syntax error') {
- die('error in RPN expression');
- } else {
- //print $ret . '<br/>';
- }
- }
- $results[2] = microtime(true) - $start;
- echo $results[2]; echo 's</p>';
- echo "<p>Using $tests[2]: ";
- $start = microtime(true);
- include_once 'Math/RPN.php';
- $start = microtime(true);
- for($i=0; $i<COUNT; $i++) {
- $expression = '1230 + 1800 + '.$i;
- $rpn = new Math_Rpn();
- if (($ret = $rpn->calculate($expression, 'deg', false)) == 'Syntax error') {
- die('error in RPN expression');
- } else {
- //print $ret . '<br/>';
- }
- }
- $results[3] = microtime(true) - $start;
- echo $results[3]; echo 's</p>';
- echo "<p>RESULTS</p>";
- echo "<p>$tests[1] is slower then $tests[0] in ".round($results[1]/$results[0])." times</p>";
- echo "<p>$tests[2] is slower then $tests[0] in ".round($results[2]/$results[0])." times</p>";
- echo "<p>$tests[3] is slower then $tests[0] in ".round($results[3]/$results[0])." times</p>";
- echo "<p>$tests[2] is slower then $tests[1] in ".round($results[2]/$results[1])." times</p>";
- echo "<p>$tests[3] is slower then $tests[1] in ".round($results[3]/$results[1])." times</p>";
- echo "<p>$tests[3] is slower then $tests[2] in ".round($results[3]/$results[2])." times</p>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement