RE: [PHP] RE: newbie alternate row colours in dynamic table -- timed tests

From: Date: Sat, 05 Apr 2003 23:45:06 +0000
Subject: RE: [PHP] RE: newbie alternate row colours in dynamic table -- timed tests
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-142547@lists.php.net to get a copy of this message
I had to know... ;-) Output: version one: 0.56761503219604 seconds version two: 0.3099730014801 seconds version three: 0.36320495605469 secondss So the boolean (V2)is faster: Mine is slightly slower by a 'smidge' (0.06 seconds) Top one is cleanest but slower. --- test --- <?php function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $ITERATIONS = 100000; $time_start = getmicrotime(); for ($i = 1; $i < $ITERATIONS; $i++) { $bgcolor = ($bgcolor == '#E3E8F0') ? '#C7D0E2' : '#E3E8F0'; } $time_end = getmicrotime(); $time1 = $time_end - $time_start; echo "version one: \t$time1 seconds<P>\n"; $time_start = getmicrotime(); $tf = TRUE; for ($i = 1; $i < $ITERATIONS; $i++) { $tf=!$tf; ($tf) ? "'C7D0E2" : "E3E8F0"; } $time_end = getmicrotime(); $time2 = $time_end - $time_start; echo "version two: \t$time2 seconds<P>\n"; $time_start = getmicrotime(); $r = 0; for ($i = 1; $i < $ITERATIONS; $i++) { (($r++ % 2 == 0) ? "'C7D0E2" : "E3E8F0"); } $time_end = getmicrotime(); $time3 = $time_end - $time_start; echo "version three: \t$time3 seconds<P>\n"; ?>

« previous php.general (#142547) next »