Clearing an array of defined element(s) - page 13

 
Maxim Kuznetsov:

Optimizer is not involved - there are half as many comparisons...

Carefully go through the tacts and see that the full coincidence of logic
ZS. I hesitated, though.
 

Just a mini refactoring ("Because you can't be so beautiful in the world..."):

#define  BENCHMARK_TEST(function, test_name)     \
   ArrayCopy(arr2,arr);                         \
   t=GetMicrosecondCount();                     \
   N=##function(arr2,Value);                    \
   t=GetMicrosecondCount()-t;                   \
   printf("вариант %-12s: Контрольная сумма = %f; элементов - %d; время выполнения - %6d микросекунд", test_name, ControlSumm(arr2), N, t);


void OnStart()
{
   srand(1);
   
   int N;
   ulong t;
   int Value=rand()%1000; // значение, которое нужно удалить из массива
   
   int arr[]; // исходный массив
   int arr2[]; // создаем еще один массив для теста и копируем в него исходный массив

   ArrayResize(arr,1000000);
   for(int i=0; i<1000000;i++){ 
      arr[i]=rand()%1000; //генерируем исходный массив случайными значениями от 0 до 1000
   }   
   
   BENCHMARK_TEST(ArrayDeleteVal1,      "Pastushak");
   BENCHMARK_TEST(arrayFilter,          "Korotky");
   BENCHMARK_TEST(DelEl2,               "Fedoseev");
   BENCHMARK_TEST(ArrayDeleteVal,       "Semko");
   BENCHMARK_TEST(ArrayModify,          "Pavlov");
   BENCHMARK_TEST(arrayFilter2,         "Nikitin");
   BENCHMARK_TEST(ArrayDelV,            "Vladimir");
   BENCHMARK_TEST(PeterArray,           "Peter");
   BENCHMARK_TEST(arrayFilter3,         "Kuznetsov");
}

//..............................................

Result:
2018.11.15 01:11:13.670 Test (EURUSD,H1)        вариант Pastushak   : Контрольная сумма = 7225.757267; элементов - 998994; время выполнения - 127587 микросекунд
2018.11.15 01:11:13.675 Test (EURUSD,H1)        вариант Korotky     : Контрольная сумма = 7225.757267; элементов - 998994; время выполнения -   2530 микросекунд
2018.11.15 01:11:13.679 Test (EURUSD,H1)        вариант Fedoseev    : Контрольная сумма = 7225.757267; элементов - 998994; время выполнения -   1995 микросекунд
2018.11.15 01:11:13.681 Test (EURUSD,H1)        вариант Semko       : Контрольная сумма = 7225.757267; элементов - 998994; время выполнения -    854 микросекунд
2018.11.15 01:11:13.686 Test (EURUSD,H1)        вариант Pavlov      : Контрольная сумма = 7225.757267; элементов - 998994; время выполнения -   3239 микросекунд
2018.11.15 01:11:13.692 Test (EURUSD,H1)        вариант Nikitin     : Контрольная сумма = 7225.757267; элементов - 998994; время выполнения -   3812 микросекунд
2018.11.15 01:11:13.698 Test (EURUSD,H1)        вариант Vladimir    : Контрольная сумма = 7225.757267; элементов - 998994; время выполнения -   4037 микросекунд
2018.11.15 01:11:13.707 Test (EURUSD,H1)        вариант Peter       : Контрольная сумма = 7225.757267; элементов - 998994; время выполнения -   7855 микросекунд
2018.11.15 01:11:13.710 Test (EURUSD,H1)        вариант Kuznetsov   : Контрольная сумма = 7224.813498; элементов - 998994; время выполнения -    744 микросекунд
Files:
 
Sergey Dzyublik:

Just a mini refactoring ("Because you can't be so beautiful in the world..."):

Just above I asked - try to put the original array as a series. ArraySetAsSeries(...,true);

This is quite a relevant question - to see which methods do not work with series at all, and which ones are unexpectedly slow

Never mind with array filtering, the question about series is more practical

 
Sergey Dzyublik:

Just a mini refactoring ("Because you can't be so beautiful in the world..."):

Thank you, Sergei, for a useful quality lesson. :)

 

Moved @Maxim Kuznetsov to a separate category, different functions after all

Recommended tests with mistakes (Semko and Pavlov).

Added your variant

P.S. And templates need to be removed, it's also a potential error when comparing doubles

Files:
 
Stanislav Dray:

Moved @Maxim Kuznetsov to a separate category, different functions after all

Recommended tests with mistakes (Semko and Pavlov).

Added your variant

P.S. Templates have to be removed too, it's potential error in comparing doubles

Made last two array elements equal to Value. Semko does not have errors. Please show us the error in what case. It is not very sensible to throw out a leader.

What are those errors with double that are caused by their normalization? So, if you work with an array of doubles, you need to worry about putting normalized data into the array yourself.

 
Dmitry Fedoseev:

Made the last two elements of the array equal to Value. Semko does not have any errors. Show me in which case he has errors. It is not fair to throw out the leader.

What are those errors with double that are caused by their normalization? If we're working with an array of doubles, we'll have to add the normalized data into the array ourselves.

I just commented in the code, you probably didn't notice it. An error if the last array element falls under the deletion condition, i.e. is equal to Value.

I haven't removed it from the code :), just to prevent someone from copying the error. I think Nikolay will correct his code and he will return himself :)

As for the templates: there will be an error when passing the double, as the function is incorrect comparison of real numbers, or rather, it is simply not intended for this, so before you put a template, we should make sure that the function will work correctly with any types.

1

 
Stanislav Dray:

I commented in the code, you probably didn't notice it. The error is if the last element of the array falls under the deletion condition, i.e. equals Value

I did not remove it from the code :), just to prevent someone from copying it with an error. I think Nikolay will correct his code and he will return himself :)

And about the templates: there will be an error when passing the double, as the function is incorrect comparison of real numbers, or rather it simply is not intended for this, so before you put a template, you should make sure that the function will work correctly with any types.


And what was there to notice? This: "array corrupted if one or more of its last elements fall under a condition"? That's what I wrote above - it didn't work. I can see from your screenshot that it's not the point. The error seems to occur when the number of items is small.

What kind of error would occur with double? Why? Whatever data is in the array will work that way. If you want it to work properly, you should perform normalization before putting it into an array. But you should not insert normalization into the function itself. The function goes perfectly well with the template and will work fine with double, if you use it correctly.

The fact that everyone has suddenly become concerned about the problem of double is very good.

 
Dmitry Fedoseev:

What was there to notice? This one: "The array is corrupted if one or more of the last elements fall under the condition"? That's what I wrote above, that it didn't work. As you can see from your screenshot, that's not the point. The error seems to occur when the number of items is small.

What kind of error would occur with double? Why? Whatever data is in the array will work that way. If you want it to work properly, you should perform normalization before putting it into an array. But you should not insert normalization into the function itself. The function goes perfectly well with the template and will work fine if you use it correctly.

The fact that everyone is suddenly concerned about the problem of double is very good, but one has to be wise about it.

You and I have different views on how the function should work. A function is a function in Africa and it should work without any data preparation, everything must work internally.

P.S. Actually no one is concerned, I'm not really bothered. I just wrote that the templates here as a dog's fifth leg and a possible error

 
Stanislav Dray:

A function is a function and should work without any data preparation, everything should work internally.

This is kindergarten.

Reason: