RSS DAILY NEWS TICKER EXAMPLE


home > overview

Brian Moon's Blog: in_array is quite slow




Brian Moon had a problem - one of his cron jobs was lasting for much longer (hours!) than it should have been. He tweaked, tested and debugged the script and finally came down to a call to in_array, something he comments on as being "quite slow".

See, this job is importing data from a huge XML file into MySQL. After it is done, we want to compare the data we just added/updated to the data in the table so we can deactivate any data we did not update. [...] We then compared the two arrays by looping one array and using in_array() to check if the value was in the second array. [...] So, that was running for hours with about 400k items. Our data did not contain the value as the key, but it could as the value was unique.

He method, replacing the in_array call that had to do a full array scan for each time through the loop with an isset/unset combo on the unique key, changed the execution time down from about 4 hours to 0.8 seconds.




click here to see original article or to find similar articles

 RSS DAILY HEADLINES

HEADLINES

Poll: Partisanship sways opinions on PalinRepublicans and Democrats have deeply contrasting first impressions of Republican vice presidential nominee Sarah Palin, suggesting partisanship, not gender, is paramount in the initial public reviews.

Briefing Book! Barack-O and Bill-O Sit Down to Chat


At least 18 dead in Cairo rockslide (AFP)

People search for survivors under the rubble of homes at the site of a massive rockslide at Moqattam hill in northern Cairo. At least 18 people were killed and 22 injured when dozens of homes collapsed after being hit by the rockslide, Egyptian emergency services said.(AFP/Khaled Desouki)AFP - At least 18 people were killed and 22 injured on Saturday when dozens of homes in northern Cairo collapsed after being hit by a massive rockslide, Egyptian emergency services said.



Find this article in Google