note 66519 deleted from function.strstr by bjori
| From: | bjori@php.net | Date: | Thu, 25 May 2006 07:43:52 +0000 |
| Subject: | note 66519 deleted from function.strstr by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-112062@lists.php.net to get a copy of this message | ||
Note Submitter: w3steve at berkeley dot edu
Reason: useless
----
Some figures on the performance of strstr vs. strpos
(my application was to test $PHP_SELF to see what set of directories an include file was being
called from)
test code:
<?php
// 24/05/2006 ss
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
// stand-in for $PHP_SELF
$myphpself = "/exampledirectory/index.php";
// run the set several times
for ($t=0; $t < 5; $t++) {
// test overhead
$time_start = getmicrotime();
for ($i=0; $i < 1000; $i++){
if ( $myphpself ) {
//do nothing, 1000 times
}
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "$time seconds for overhead<br>\n";
// test strpos
$time_start = getmicrotime();
for ($i=0; $i < 1000; $i++){
if ( strpos($myphpself, 'example')) {
//do nothing, 1000 times
}
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "$time seconds to test strpos 1k times<br>\n";
// test strstr
$time_start = getmicrotime();
for ($i=0; $i < 1000; $i++){
if ( strstr($myphpself, 'example')) {
//do nothing, 1000 times
}
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "$time seconds to test strstr 1k times<br>\n";
// test strpos !== FALSE
$time_start = getmicrotime();
for ($i=0; $i < 1000; $i++){
if ( strpos($myphpself, 'example') !== FALSE) {
//do nothing, 1000 times
}
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "$time seconds to test strpos !== FALSE 1k times<br>\n<br>\n";
}
?>
Results:
0.00107002258301 seconds for overhead
0.00192594528198 seconds to test strpos 1k times
0.00201010704041 seconds to test strstr 1k times
0.00249099731445 seconds to test strpos !== FALSE 1k times
0.00104904174805 seconds for overhead
0.00189995765686 seconds to test strpos 1k times
0.00197291374207 seconds to test strstr 1k times
0.00248503684998 seconds to test strpos !== FALSE 1k times
0.0010449886322 seconds for overhead
0.00186109542847 seconds to test strpos 1k times
0.00201511383057 seconds to test strstr 1k times
0.00245690345764 seconds to test strpos !== FALSE 1k times
0.000998020172119 seconds for overhead
0.00183892250061 seconds to test strpos 1k times
0.00199389457703 seconds to test strstr 1k times
0.00246500968933 seconds to test strpos !== FALSE 1k times
0.0010449886322 seconds for overhead
0.00184917449951 seconds to test strpos 1k times
0.00199913978577 seconds to test strstr 1k times
0.00242614746094 seconds to test strpos !== FALSE 1k times