say i was trying to append a % before any occurance of either abc,
abd, or abe, in a string. which would be faster?:
$string = str_replace("ab c","%abc",$stri ng);
$string = str_replace("ab d","%abd",$stri ng);
$string = str_replace("ab e","%abe",$stri ng);
or
$string - preg_replace("/(abc|abd|abe)/","%$1",$string );
php.net says that preg_replace is slower than one str_replace, but for
multiple ones, it seems like it would gain a slight speed advantage.
also, exactly how would the following to code segments compare, speed
wise?
for ($num=0;$num<$l ength;$num++) {
$array1[] = $num;
$array2[] = $num;
}
for ($num=0;$num<$l ength;$num++)
$array1[] = $num;
for ($num=0;$num<$l ength;$num++)
$array2[] = $num;
it seems like the first one should require 3*$length operations,
whereas the first one would require 4*$length operations, although i'm
not 100% sure on that.
abd, or abe, in a string. which would be faster?:
$string = str_replace("ab c","%abc",$stri ng);
$string = str_replace("ab d","%abd",$stri ng);
$string = str_replace("ab e","%abe",$stri ng);
or
$string - preg_replace("/(abc|abd|abe)/","%$1",$string );
php.net says that preg_replace is slower than one str_replace, but for
multiple ones, it seems like it would gain a slight speed advantage.
also, exactly how would the following to code segments compare, speed
wise?
for ($num=0;$num<$l ength;$num++) {
$array1[] = $num;
$array2[] = $num;
}
for ($num=0;$num<$l ength;$num++)
$array1[] = $num;
for ($num=0;$num<$l ength;$num++)
$array2[] = $num;
it seems like the first one should require 3*$length operations,
whereas the first one would require 4*$length operations, although i'm
not 100% sure on that.
Comment