Get the number of decimal places of any numbers (not just quotes) bypassing Digits() in MQL4 and MQL5 - page 15

 
Igor Makanu:

if ArrayCopy() is done in the same way as Cysh memmove(),

I think the speed of ArrayCopy() depends on the speed of memory allocation, if the intermediate buffer memory is ready for copying, ArrayCopy() will be executed very quickly, if the memory is not allocated, you will start requests to the operating system to allocate memory

you can try to test it - make one call to ArrayCopy() with a large data volume, thereby preparing the buffer memory for swapping, and then make a loop with ArrayCopy() with smaller data volume to be copied and then measure the speed

In our current example, copying is executed in a static array, but in general it is interesting, of course, when ArrayCopy is slower than a simple for. If you need to allocate memory, you'll have to do it anyway, no matter how you do it.

 
Ilya Malev:

In our current example, copying is performed to a static array, but in general it is interesting, of course, when ArrayCopy is slower than simple for. If we need to allocate memory, we'll have to do it anyway.

It doesn't matter static or dynamic, we don't know how ArrayCopy() is implemented, I just assumed that it's a "wrapper" over standard Cish functions, memmove() usually works via additional buffer... well, as usual, that's how it was written before, it's hard to tell how and which compiler works

SZY: I just don't know how to test the runtime in MQL ((( - I've tried it a couple of times, I think I've taken examples from help, the results are somehow very different, and I've ignored this question out of necessity - I don't test the performance, I usually look in the profiler, what and how is executed in time

 
Igor Makanu:

I just do not know how to test the execution speed in MQL ((( - I tried it a couple of times, I think I took examples from the help, but the results were very different for some reason, and I gave up on this issue because I do not test the performance, I usually use the profiler to see how and what is executed in time

here is the easiest way, which I used above

#property strict

#define    test(M,S,EX)        {uint mss=GetTickCount();int nn=(int)pow(10,M);for(int tst=0;tst<nn;tst++){EX;} \
                                printf("%s: loops=%i ms=%u",S,nn,GetTickCount()-mss);}

void OnStart()
 {
  int arr1[100]={0},arr2[100]={0};
  test(7,"Копирование через ArrayCopy",ArrayCopy(arr1,arr2))
  test(7,"Копирование через for",for(int i=0;i<100;i++)arr1[i]=arr2[i])
 }  


 
Ilya Malev:

here's the easiest way i used above


Thanks, got it, I'll test it tomorrow

 
Ilya Malev:

Yes, this will work much faster (replaced for where possible by ArrayCopy, the rest is the same):

I told you, I wrote the first thing that came to mind without any tests))

This variant is no different from mine. Measurements (minimum time out of 10 tries) prove it.

https://www.mql5.com/ru/forum/287618/page14#comment_9807465
TicksToIntArray_fxsaber2
Time[TicksToIntArray(TicksIn,Array)] = 301036
IntArrayToTicks_fxsaber2
Time[IntArrayToTicks(Array,TicksOut)] = 315109
true

https://www.mql5.com/ru/forum/287618/page14#comment_9808274
TicksToIntArray_antfx1
Time[TicksToIntArray(TicksIn,Array)] = 216101
IntArrayToTicks_antfx1
Time[IntArrayToTicks(Array,TicksOut)] = 203610
true

https://www.mql5.com/ru/forum/287618/page14#comment_9810247
TicksToIntArray_antfx2
Time[TicksToIntArray(TicksIn,Array)] = 303656
IntArrayToTicks_antfx2
Time[IntArrayToTicks(Array,TicksOut)] = 312008
true

You can see that variant with cycle is faster, because cycle of 60 /4 = 15 elements.

Files:
 
fxsaber:

This variant is no different from mine.

Apparently yes, only the structure type and array type are arbitrary.

 
fxsaber:

You can see that the loop variant is faster, because the loop of 60 /4 = 15 elements.

Strangely enough, I got faster than ArrayCopy with the same MqlTicks and int...

 
Ilya Malev:

Strangely, I got faster than ArrayCopy with the same MqlTicks and int...

I'm running it in MT5x64.

Ilya Malev:

Apparently, yes, but the structure type and array type are arbitrary.

I purposely avoided the common case to allow more people to participate.


So far

https://www.mql5.com/ru/forum/287618/page14#comment_9808274
TicksToIntArray_antfx1
Time[TicksToIntArray(TicksIn,Array)] = 213426
IntArrayToTicks_antfx1
Time[IntArrayToTicks(Array,TicksOut)] = 202693
true

https://www.mql5.com/ru/forum/287618/page14#comment_9807465
TicksToIntArray_fxsaber3
Time[TicksToIntArray(TicksIn,Array)] = 192362
IntArrayToTicks_fxsaber3
Time[IntArrayToTicks(Array,TicksOut)] = 159932
true
 
fxsaber:

Running in MT5x64.

Purposely bypassed the general case so that more people could participate.


So far.

I guess your code is already faster :)

I have to add a lot of service code there to improve functionality of ArrayCopy (source start, dest start, count) and check parameters for correctness...

In general, you have so many cool works/libraries that it's strange that you ask and discuss the best solution on the forum :)

 
Ilya Malev:

It's strange that you ask and discuss the best solution on the forum :)

I need one for the HistoryTicks library. Thank you for participating.

Reason: