XML parsing speed up. PHP -
i'm here ask concepts can make process faster:
foreach($xml->results->concepts->concept $value2){//this original game. $total_concepts++; foreach($xml1->results->concepts->concept $value1){//this similar game. $total_similar_concepts++; if(strcmp($value2->name, $value1->name)==0){ $comparisons++; break; } } }
essentially, i'm comparing each 'concept' of original game each 'concept' of each 'similar' games.
this algorithm takes 11.6 seconds on average complete. there can make run faster? thinking perhaps parsing xml wasn't best do.
the xml parsing unlikely reason problem. if has xml it's i/o, meaning takes long fetch data disk.
what doing combining elements in $xml elements in $xml2 o(n^2) complexity problem. can try reduce complexity making use of hashmap, easy in php because got associative arrays hashmaps:
foreach($xml->results->concepts->concept $value2) { $total_concepts++; $map[(string)$value2->name] = true; } foreach($xml1->results->concepts->concept $value1) { $total_similar_concepts++; if (isset($map[(string)$value1->name])) $comparisions++; }
in best case gives o(2n) complexity, better previous version.
Comments
Post a Comment