arrays - PHP Greatly speed up execution time of my script -


I have a heavy script that we go a lot, the algorithm below has been used:

  1. Load 4500 rows from the database and store them as an array (A)

  2. Load 600000 rows from the database and place them in the array Store in the form. (B)

  3. (A) looks for a match (B) for each element.

  4. Next, the maximum amount of this script is 4500 * 60 000, which is 270 million, so you can understand that it may be a bit sweat for PHP.

    Can I make this process efficient in any way? Reading rows from the database is not really an issue, this array is iterative which brings huge cost.

    It works very fast, but a factor (60000) will increase greatly in the coming years.

    Any ideas?

    Here are a few different answers. My guess is that the first one is correct, easy and sufficient, But it is very difficult to make sure.

    Possible answer 1: Use of SQL

    As the comments indicate, it looks like a lot to be included. Apart from this, your post indicates that when a match is received, you only take one action and there are no ments matches in A. This means that your SQL statement should only return lines of matching, not all of them.

    Potential Answer 2: Sort Array

    Maybe you can do this, it does not matter that you can not do everything in SQL. Sort arrays (again, to your database to do this) Probably you can sort B so that the search for a match is sharp. Or enter the search value in the key of the array so that the search is very quick. Or if you are lucky then you may be able to sort both arrays in a manner that makes all A and B in the same order i.e. for any A you know that the right b is not in existence either Or B is not present later in the head.

    Possible answer 3: Tell more about the problem

    You have only given us your current algorithm, and not exactly what you are trying to do most likely it That's not the best idea to walk on everything, but no one can say so until they know more about your data and what you want to do at the end.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -