php - Optimizing array merge operation -


I appreciate any help.

I have approximately 7 different arrays. I have 90,000 numbers in each array (we call them arrays1-arrays7). There is no duplicate number within each array, but duplicates between arrays can be duplicated. For example, array 2 does not have any duplicates, but with arrays3 and arrays4 it is possible in the same number.

Problem: I'm trying to identify duplicated numbers of all 7 arrows once in a merging class.

I want to make this calculation 1000 times and it takes 15 minutes but that's not okay because I have to run it 40 times - Code:

If you have any other language I know this is most suitable for calculation of this type. Please tell me some extension suggestions like redis or gearman are useful. For

  ($ kj = 1; $ kj & lt; = 1000; $ kj ++) {$ result = array_merge ($ files_array1, $ files_array2, $ files_array3, $ files_array4, $ Files_array5, $ files_array6, $ files_array7); $ Result = array_count_values ​​($ result); $ Fp_lines = fopen ("equalTo3.txt", "w"); Forex Currency ($ $ $ Key => $ val) {If ($ result [$ key] == 3) {Fit ($ fp_lines, $ key) "\ r \ n"); }} Fclose ($ fp_lines); }  

I have tried the code below with the strings but arr_map call and array_count value call for 17 minutes:

 for  ($ kj = 1; $ Kj & lt; = 1000; $ kj ++) {$ Result = ''; For ($ ii = 0; $ ii & lt; 7; $ ii ++) {$ Result = $ Files_array [$ hello_won [$ ii]]. '\ R \ n'; } $ Result2 = Explosion ("\ n", $ result); // 5mins $ result2 = array_map ("trim", $ result2); // 11mins $ result2 = array_count_values ​​($ result2); // 4-6mins $ fp_lines = FOPN ("BarBarTO3WT", "W"); Forex currency ($ key as $ result2 & gt; $ val) {if ($ result2 [$ key] == 3) {FILIT ($ fp_lines, $ key. "\ R \ n"); }} Fclose ($ fp_lines); Not set ($ result2);  

/////////////////////////////////////// ////////////

@jymin @ Change @scunalaffe @ this.lau_ @monocell Thanks to everyone and for any other person posting !! I am working through all your suggestions and work through all the replies after yesterday's reply. Thanks a lot!

array_arug () is much slower with more elements because in the array ( From:)

If the input arrays have the same string key, the subsequent values ​​for that key will overwrite the previous one, however, if there are numeric keys in the arrays, then the later Values ​​will not overwrite the original value, but will be added.

In the input array with the numeric key, the result array with the values ​​starting from zero.

Then this function is actually making some conditional statement that you can change the merge of the array with the addition of normal, loop (foreach or any other) and [] < / Code> operator. You can write functions by copying array_merge (such as using the reference not to copy the array.):

  function imitateMerge (& $ array1, & $ array2) { Foreach ($ array2 as $ I) {$ array1 [] = $ i; }}  

And you will actually see an increase in the speed of the speed.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -