Advise language, syntax similar to PHP, which will quickly perform operations with arrays.

I produce comparisons of several arrays, about 200 by 200, and I have no strength to wait for the PHP code to execute. Maybe there is some kind of language that will be considered much faster and specifically for the sake of one task will not have to learn it?

  • one
    200 by 200 is a rather small size. You probably have a problem with the algorithm. - Vladimir Gordeev
  • (Looking at the "PHP" tag) And what is meant by arrays? And the fact that PHP is called “arrays” is, in general, the dog will understand that the pen is on the side. - drdaeman
  • @drdaeman a certain array [$ x] [$ y] - trashmajor

3 answers 3

Regarding your comments, sorry not noticed before. And what do you want to get as a result of the algorithm?


I can offer two ways. The second is more interesting, but not every task can be applied. Try it.

1. There is no typing of variables in PHP, so it spends a lot of resources trying to figure out how to do it and do it))

You will experience a performance boost even in Ruby or Java, not to mention C ++ compiled types))

As for syntax similarity ... Well, there is a very close Perl - it also often happens on hosting ... But I'm not sure that you write a program on it right away - it’s still very different .. And there are also questions about speed .

I would still recommend implementing the main functionality on PHP, and implementing the comparison operations themselves in C ++ and calling them via the CGI interface with redirects ...

2. And the second point - try to build the data in this way (even if you have to repartition it for several, etc.), so that you can use the standard PHP functions array_intersect and array_diff - they will work much faster than nested loops.

    @trashmajor , i.e. Are you looking for (apparently in nested loops) a matrix of about 100x100 in size inside a matrix of 200x200, trimming the first (if not found) and everything repeats?

    I am afraid that (especially if it comes to the phase of cutting the columns of matrix 2) no language can dramatically speed up the process.

    Apparently it is necessary to rework the algorithm. To begin with, I would think about finding the right lower element of array-2 in array-1 and compare the matrices already from this point.

    In fact, a lot depends on the “nature” of the data. And also, how often do you look for different source materials in the same array-1?

    If often, then you can think about indexing the elements of array-1 to speed up the search for starting points for comparing matrices.

      C, C ++. Maybe it is worth optimizing the algorithm? Indeed, as written, your size is small in order to start swearing at PHP.

      • I first look for array-2 in array-1, if I don’t find it, delete the row from array-2 and look again in array-1. I continue to delete by line until I find array-2 in array-1. If the row is left alone, return the rows back and delete the column from the array-2. Looking again. Delete the column until I find it. - trashmajor
      • one
        you can not start to delete the column / row, but simply correct the indexes for the cycle. This will accelerate. But if you delete a line (I understand the top one?), Can it start a search from bottom to top before the first difference? and will not need to be deleted. - KoVadim