|
Posted by Wolverine on 04/26/06 05:49
It turns out it is almost twice as fast to build the two arrays of all
users and do one str_replace. Using PEAR's benchmarking I ran stats
and it showed the following method:
$uid_search = array();
$uid_replace = array();
foreach ($result as $key => $arr) {
array_push($uid_search, ';u='.$arr->ID_MEMBER.'"');
array_push($uid_replace, ';user='.$arr->id.'"');
}
$buffer = str_replace($uid_search, $uid_replace, $buffer);
to be faster in every test... nearing twice as fast to this
method(which is adapted from your suggestion, thanks!):
foreach ($result as $key => $arr) {
$arr_user_ids[$arr->ID_MEMBER] = $arr->id;
$buffer = str_replace(';u='.$arr->ID_MEMBER.'"',
';user='.$arr->id.'"', $buffer);
}
I'm happy with the result. It seems the most expensive thing is call
to run preg_replace or str_replace. Best to pack every single thing
you need into the search and replace arrays before calling these
methods.
I wish I had a memory benchmarking tool but I don't think this would
ever come close to the 6MB limit.
Thanks again for the help!
Navigation:
[Reply to this message]
|