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

McCain-Palin becoming Palin-McCain?

Sen. John McCain, his wife, Cindy, right, andAlaska Gov. Sarah Palin take the stage at a campaign rally in Colorado Springs, Colo., on Saturday.The banners, buttons and signs say McCain-Palin, but the crowds say something else.


One Last Look at the Republican Convention: the Balloon Drop!

I was listening to McCain's nomination acceptance speech on the radio on the way to the airport yesterday and it sounded so different than it did in the arena. I actually got to hear the fiery end to the speech, the part where he said:

Stand up, stand up, stand up and fight. Nothing is inevitable here. We're Americans, and we never give up. We never quit. We never hide from history. We make history.

In the arena that night, the whole last minute was drowned out by cheers — and then when the soaring music swelled, the confetti rained down as the harbinger of balloons and the hopeful first family took the stage, forget about it — it was a perfect end to a convention that last Monday, no one even knew if it would happen. But it did, and I'm so glad to have been there.

To see the balloon drop,

read more

FBIs civil rights initiative: no trials yet (AP)

This undated file photo shows civil rights workers Michael Schwerner,  left, James Chaney, and Andrew Goodman, right, who disappeared near Philadelphia, Miss., June 21,1964. The three civil rights workers were abducted, killed and buried in an earthen dam in rural Neshoba County. In 2005, Edgar Ray Killen was convicted of three counts of manslaughter for orchestrating the killings. (AP Photo/FBI,File)AP - Flanked by officials from the NAACP and the Southern Poverty Law Center, FBI Director Robert Mueller last year announced with considerable fanfare a new partnership between his agency and civil rights organizations.



Find this article in Google