note 57561 added to function.explode

From: Date: Fri, 07 Oct 2005 12:17:08 +0000
Subject: note 57561 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-96551@lists.php.net to get a copy of this message
//new quick lastword-function demonstration of the fastest way possible! if (!function_exists('microtime_float')) { function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } } function lastwordOLD($string,$seperator=" ") {//last word of an string $array = explode($seperator, $string); $number = count($array); if($number>0) { $number--; return $array[$number]; } return; } //low memory/cpu/parsetime-usage-version of lastword function lastword($string,$seperator=" ") {//last word of an string return substr($string,strrpos($string,$seperator)); } //letz check how good is the new function instead of the old... $time_start = microtime_float(true); print "<br><br>lastwordOLD:"; print "<br>needle included: ".lastwordOLD("hans peter susi luci");//output needle included: luci print "<br>needle not included: ".lastwordOLD("hans;peter;susi;luci");//output needle not included: hans;peter;susi;luci print "<br>runtime-usage x10000: "; $aa=0; while($aa<10000){ $aa++; $request=lastwordOLD("hans peter susi luci"); $request=lastwordOLD("hans;peter;susi;luci"); } $time_end = microtime_float(); $timeOLD = $time_end - $time_start; print $timeOLD; $time_start = microtime_float(true); print "<br><br>lastword(new):"; print "<br>needle included: ".lastword("hans peter susi luci");//output needle included: luci print "<br>needle not included: ".lastword("hans;peter;susi;luci");//output needle not included: hans;peter;susi;luci print "<br>runtime-usage x10000: "; $aa=0; while($aa<10000){ $aa++; $request=lastword("hans peter susi luci"); $request=lastword("hans;peter;susi;luci"); } $time_end = microtime_float(); $time = $time_end - $time_start; print $time; //the result is... print "<br><br>you spare with this script and using new function instead of old: ".($timeOLD-$time)." sec."; //you will see the parsetime of new function procedere will be circa a half of the old! // //result of my webserver , running on an pentium4 2800mhz with suse9 // //lastwordOLD: //needle included: luci //needle not included: hans;peter;susi;luci //runtime-usage x10000: 0.15616607666 // //lastword(new): //needle included: luci //needle not included: hans;peter;susi;luci //runtime-usage x10000: 0.0851180553436 // //you spare with this script and using new function instead of old: 0.0710480213165 sec. ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57561 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57561&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57561&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57561&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57561&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57561&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57561&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57561&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57561&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96551) next »