RE: [PHP] echo vs printf

From: Date: Mon, 16 Jul 2001 17:50:24 +0000
Subject: RE: [PHP] echo vs printf
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-58093@lists.php.net to get a copy of this message
> 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

« previous php.general (#58093) next »