AlgLib contains ArrayReverse functions

 

I have noticed, AlgLib from standard library overwrites the original functions from MQL.

Interestingly, it doesnt make any sense, because the included function is slower than the original MQL-Function.


//+------------------------------------------------------------------+
//| Array reverse (uchar)                                            |
//+------------------------------------------------------------------+
//void ArrayReverse(uchar &array[])
bool _ArrayReverse(uchar &array[])
  {
//--- size
   int size=ArraySize(array);
//--- half of size
   int half=size/2;
//--- create a variable
   uchar temp;
//--- reverse
   for(int i=0;i<half;i++)
     {
      temp=array[i];
      array[i]=array[size-1-i];
      array[size-1-i]=temp;
     }
  return(true);
  }
//+------------------------------------------------------------------+
//| Array reverse (bool)                                             |
//+------------------------------------------------------------------+
//void ArrayReverse(bool &array[])
bool _ArrayReverse(bool &array[])
  {
//--- size
   int size=ArraySize(array);
//--- half of size
   int half=size/2;
//--- create a variable
   bool temp;
//--- reverse
   for(int i=0;i<half;i++)
     {
      temp=array[i];
      array[i]=array[size-1-i];
      array[size-1-i]=temp;
     }
  return(true);
  }



template <typename T>
void perf_call(const ulong start, T retval, const ulong end)
{ printf("Time in microseconds: %llu", (end > start) ? (end - start) : (start - end)); }


uchar uc_arr[5000000];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    for(int cnt = NULL; (cnt < 5000000) && !_StopFlag; cnt++)
    { uc_arr[cnt] = (uchar)MathRand(); }

    perf_call(GetMicrosecondCount(), _ArrayReverse(uc_arr), GetMicrosecondCount());

    for(int cnt = NULL; (cnt < 5000000) && !_StopFlag; cnt++)
    { uc_arr[cnt] = MathRand(); }

    perf_call(GetMicrosecondCount(), ArrayReverse(uc_arr), GetMicrosecondCount());

    return(INIT_FAILED);
}


As can be seen by this test.

Here are the results:

Time in microseconds: 1941
Time in microseconds: 1380


I would like to ask Metaquotes Dev team alter the file: /Include/Math/Alglib/bitconvert.mqh

Please add at line 326:

#ifndef __MQL5__

and at line 361:

#endif


This will exclude the functions overwriting from MQL5 builds.

 

The "AlgLib" Standard library is older than the more recent builds of MQL5. So, MetaQuotes would have to rewrite it again, and given their priorities, it will be some time before that is done.

 
Fernando Carreiro #:

The "AlgLib" Standard library is older than the more recent builds of MQL5. So, MetaQuotes would have to rewrite it again, and given their priorities, it will be some time before that is done.

Yes, I suspect same...

Although it be two lines to add...