> As I understand it, echo is not a function it's a
   > language something or other, supposedly it runs
   > slightly faster than print given the same output.
 
<?php
class xTimer{
    var $time_start;
    var $time_delta; 
    
    function Start(){
        $this->time_start = $this->GetMicroTime();
    }

    function Stop(){
        $time_end = $this->GetMicroTime();
        $this->time_delta = $time_end - $this->time_start;
        return $this->time_delta;
    }

    function GetMicroTime(){
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
}
    
print "echo vs print test<br>\n";
$string = "foo ";
$iter = 1000000;
$t = new xTimer;
$t->Start();
for($i = 0; $i < $iter; $i++){
    print $string;
}
$print_time = $t->Stop();
        
$t->Start();
for($i=0; $i < $iter; $i++){
    echo $string;
}
$echo_time = $t->Stop();

print "\n<br>print printing $iter times: $print_time<br>\n";
print "\n<br>echo printing $iter times: $echo_time<br>\n";
?>

Results:
Test1:
print printing 1000000 times: 2.829174041748
echo printing 1000000 times: 3.683454990387

Test2:
print printing 1000000 times: 3.131462931633
echo printing 1000000 times: 2.8942189216614

Test3:
print printing 1000000 times: 5.127711057663
echo printing 1000000 times: 5.5264019966125

HW, Dell rackmount Server, dual CPU running Linux 2.2.16.

--Kent


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to