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

 
Алексей Тарабанов:

Don't make fun of people

Didn't even start ;-)

I didn't even mention the "checksum" when there's a benchmark.

One can remember about asymptotics, by which the speed is finally estimated.
And that it depends on the amount of input data, the number of elements to be removed and their location/distribution (which in reality is NEVER uniform).

and that graphs can/should be plotted.

the target is certainly not worth the effort, but somehow the methodology should be followed

I could go on for another two or three pages :-)

 

Added rotation, pauses and warm-up option (first pass is not counted)

Files:
 
Stanislav Dray:

I've added a variant with rotation, pauses and warm-up (the first pass is not taken into account)

It's strange that many examples can't work properly with structures... Maybe I don't understand something...

 
Vladimir Pastushak:

It's strange that many examples can't work properly with structures... Maybe I don't understand something...

Get rid of structures in favor of classes. They are easier to work with in MQL.

 
Vladimir Pastushak:

It's strange that many examples can't work properly with structures... Maybe I don't understand...

What do you mean? I don't know what you mean. What examples don't work right? Everything works.

1

 
Vladimir Pastushak:

It's strange that many examples can't work properly with structures... Maybe I don't understand something...

The functions don't know which field of the structure should be compared.

 
Dmitry Fedoseev:

The function does not know which field of the structure is to be compared.

The function is comparing by fields. The result is the deletion of the last element in the array for some reason.

 
Figured it out, it was the field shifting in the string, not the whole structure...
 
Nikolai Semko:

Study the code.

Checked your code. You did everything right.

I just don't understand why that line takes the lion's share of my time:

//+------------------------------------------------------------------+
int PeterArray(int &Arr[],const int val) // вариант Peter Konow
  {
   int deleted=0,q=0;
   for(int a1=0; a1<ArraySize(Arr); a1++)
     {
      if(deleted)Arr[q]=Arr[q+deleted];
      if(Arr[q]==val){deleted++; q--;} <-----------Выполнение этих операций занимает кучу времени.
      q++;
     }
   ArrayResize(Arr,q);
   return (q);
  }
//+------------------------------------------------------------------+

Without that line, the code runs in 2 microseconds. But you can't do it without it.

It may not be the fastest solution, but it is one of the most concise.


SZY. You made one mistake when writing the function by my solution:

My function is not

ArrayResize(Arr,q);

а

ArrayResize(Arr,ArraySize(Arr) - deleted);

But thanks anyway.

 
Vladimir Pastushak:

The function is comparing fields. The result is, for some reason, the last element in the array is deleted.

When assigning one element to another, i.e. when using "=" sign?

I've noticed that, it's better to do your own copying. You can't rely on anything.

Reason: