PHP Hashtable array optimisation.
Posted
by
hiprakhar
on Stack Overflow
See other posts from Stack Overflow
or by hiprakhar
Published on 2011-03-10T14:06:18Z
Indexed on
2011/03/10
16:10 UTC
Read the original article
Hit count: 359
I made a PHP app which was taking about ~0.0070sec for execution. Now, I added a hashtable array with about 2000 values. Suddenly the time for execution has gone up to ~0.0700 secs. Almost 10 times the previous value.
I tried commenting out the part where I was searching inside the hashtable array (but array was still left defined). Still, the execution time remains about ~0.0500secs.
Array is something like:
$subjectinfo = array(
'TPT753' => 'Industrial Training',
'TPT801' => 'High Polymeric Engineering',
'TPT802' => 'Corrosion Engineering',
'TPT803' => 'Decorative ,Industrial And High Performance Coatings',
'TPT851' => 'Project');
Is there any way to optimize this part?
I cannot use Database as I am running this app on Google app engine which is still not supporting JDO database for php.
Some more code from the app:
function getsubjectinfo($name)
{
$subjectinfo = array(
'TPT753' => 'Industrial Training',
'TPT801' => 'High Polymeric Engineering',
'TPT802' => 'Corrosion Engineering',
'TPT803' => 'Decorative ,Industrial And High Performance Coatings',
'TPT851' => 'Project');
$name = str_replace("-", "", $name);
$name = str_replace(" ", "", $name);
if (isset($subjectinfo["$name"]))
return "(".$subjectinfo["$name"].")";
else
return "";
}
Then I am using the following statement 2-3 times in the app:
echo $key." ".$this->getsubjectinfo($key)
© Stack Overflow or respective owner