How do I add to an array from a static method?

In php, will storing an array use less or more memory than an sql query for the same purpose?

  • I'm the developer of CSV 2 POST Pro for Wordpress and I want to speed it up. It imports hundreds of thousands of records and so the slightest improvement in my script can greatly increase performance. I only finished University last year so theres no way I'm going to know stuff like this. If I have a group of settings stored in database then make a querie and hold the results for accessing 100,000 times. Would this be better or worse than having an array ( don't worry about where the array comes from at this point) and accessing that 100,000 times? For Wordpress developers, the array would come from options so although the question is not regarding the speed of the method in obtaining the data please feel free to add any info on. I'm thinking wordpress get_option can't be faster than a direct sql query so its the long term use of the resulting data I REALLY need to know. Thanks all WebTechGlobal

  • Answer:

    I don't know much about PHP, but it seems like itll all come down to the same thing in the end. You're saying that you want to either a) query a database 100,000 times and hold the results (which I assume you're going to be using some form of array to do this) or (this is where i get confused) b) have a preloaded array with all the results of the queries you wouldve made? Where would that preloaded array have come from? It has to be initialized somewhere. So in the end, if i interpreted it right, you'll have the same amount of data in memory at the end. The running time would be slightly better in b), but thats assuming youve hardcoded the array your accessing in your code. Otherwise, running time will be the same, because to get that array filled you'll need to query your database the same amount of times. Looks to me like you're attempting to solve the problem two times in the same way. When importing into an array, if you're filling every member, then the speed of your code will never be better than O(n) time. And assuming each time youre entering your query takes time, then your code will never be faster than querytime * n where n is the number of items youre importing into the array. So if it takes 3s for each query(it shouldnt) and you have 100,000 items then your code will take 300,000s or 5000 minutes or 83.33 hours. Sorry if i wasnt of any specific help, im just trying to give you ideas of how to approach your problem.

WebTechG... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

comes down to time: 1 massive query (say .3 mil secs) or multiple queries (.1 mil sec) and network latency (speed) etc. I would do multiple queries so you can pull different data depending on the operation (not storing all of the information in one huge array thus freeing up server RAM etc.)

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.