<pre>
<?php

/**
 * Simple benchmarking for Variables vs Constants
 * See related blog post : http://planetozh.com/blog/2006/06/php-variables-vs-constants/
 */


/* Define functions */

function timer_start() {
    global $timestart;
    $mtime = microtime();
    $mtime = explode(' ',$mtime);
    $mtime = $mtime[1] + $mtime[0];
    $timestart = $mtime;
    return true;
}

function timer_stop($display = 0, $precision = 3) {
    global $timestart, $timeend;
    $mtime = microtime();
    $mtime = explode(' ',$mtime);
    $mtime = $mtime[1] + $mtime[0];
    $timeend = $mtime;
    $timetotal = $timeend-$timestart;
    if ($display)
        echo number_format($timetotal,$precision);
    return $timetotal;
}

function testvar($loop) {
    global $val0,$val1,$val2,$val3,$val4,$val5,$val6,$val7,$val8;
    for ($i=0;$i<$loop;$i++) {
        $test = ((sin($val0 * $val1 + $val2))/$val6 * (sqrt( log($val3) * abs($val4 - 1/$val5)) / $val7)) * $val8;
    }
}

function testarr($loop) {
    global $arrayval;
    for ($i=0;$i<$loop;$i++) {
        $test = ((sin($arrayval[0] * $arrayval[1] + $arrayval[2]))/$arrayval[6] * (sqrt( log($arrayval[3]) * abs($arrayval[4] - 1/$arrayval[5])) / $arrayval[7])) * $arrayval[8];
    }
}

function testconst($loop) {
    for ($i=0;$i<$loop;$i++) {
        $test = ((sin(VAL0 * VAL1 + VAL2))/VAL6 * (sqrt( log(VAL3) * abs(VAL4 - 1/VAL5)) / VAL7)) * VAL8;
    }
}

/* Define variables, arrays and constants */

$loop = 10000;

$val0 = 11;
$val1 = 33.5;
$val2 = 0.333333333333;
$val3 = 4569988.2;
$val4 = 159;
$val5 = 2.33333333333;
$val6 = -10;
$val7 = -6.6;
$val8 = -1245487545;

define(VAL0,11);
define(VAL1,33.5);
define(VAL2,0.333333333333);
define(VAL3,4569988.2);
define(VAL4,159);
define(VAL5,2.33333333333);
define(VAL6,-10);
define(VAL7,-6.6);
define(VAL8,-1245487545);

$arrayval[0]=11;
$arrayval[1]=33.5;
$arrayval[2]=0.333333333333;
$arrayval[3]=4569988.2;
$arrayval[4]=159;
$arrayval[5]=2.33333333333;
$arrayval[6]=-10;
$arrayval[7]=-6.6;
$arrayval[8]=-1245487545;

/* Let's run a few tests now */

echo 'test with PHP '.phpversion();
echo "<hr>\n";

/**
 * Straight Tests
 */

echo '<h1>lots of vars</h1>';

timer_start();
for($i=0;$i<$loop;$i++) {
    $test = ((sin($val0 * $val1 + $val2))/$val6 * (sqrt( log($val3) * abs($val4 - 1/$val5)) / $val7)) * $val8;
}
echo 'straight, variables : ';timer_stop(1,9);
echo "<hr>\n";


timer_start();
for($i=0;$i<$loop;$i++) {
    $test = ((sin($arrayval[0] * $arrayval[1] + $arrayval[2]))/$arrayval[6] * (sqrt( log($arrayval[3]) * abs($arrayval[4] - 1/$arrayval[5])) / $arrayval[7])) * $arrayval[8];
}
echo 'straight, array: ';timer_stop(1,9);
echo "<hr>\n";


timer_start();
for($i=0;$i<$loop;$i++) {
    $test = ((sin(VAL0 * VAL1 + VAL2))/VAL6 * (sqrt( log(VAL3) * abs(VAL4 - 1/VAL5)) / VAL7)) * VAL8;
}
echo 'straight, constants: ';timer_stop(1,9);
echo "<hr>\n";

/**
 * Function call and a global statement
 */

echo '<h1>function(lots of vars)</h1>';

timer_start();
testvar($loop);
echo 'function call, variables: ';timer_stop(1,9);
echo "<hr>\n";

timer_start();
testarr($loop);
echo 'function call, array: ';timer_stop(1,9);
echo "<hr>\n";


timer_start();
testconst($loop);
echo 'function call, constants: ';timer_stop(1,9);
echo "<hr>\n";

?>