question for #define experts - page 11

 
Igor Makanu:

if physically in the CPU command, no

an array is a memory area, access to array elements is to calculate an index of an element from the beginning of this memory area and retrieve data (bytes) according to the stored type


if this is the logic of the algorithm, then yes - these are indexable variables

in general on the problem under study, the only correct advice is https://www.mql5.com/ru/forum/354662/page4#comment_19039624:

     {
      for(int i=0; i<ArraySize(mas); i++)
        {  
        r2+=ArraySize(mas);
        r2|=ArraySize(mas); 
        }

     }  
   ulong t2=GetMicrosecondCount();
   //for(ulong z=0; z<max; z++)
   int sizem=ArraySize(mas);
     {
      for(int i=0; i<sizem; i++)
        { 
        r2+=sizem;
        if (r2>10) r2|=sizem; 
        }
     } 

The execution time of a binary operation is many times faster than the execution time of an if statement (it should be) .... Looks like behind the scenes either clean or super fast native code

The time of the top one is half that of the bottom one.


Well technically we were comparing two variables))

 
Alexandr Andreev:

The execution time of a binary operation is many times faster than the execution time of an if statement (it should be so) ....

there should be no if() in loops , earlier the loop was executed by the CX register

Alexandr Andreev:

The time of the upper one is half as much as that of the lower one

I'm not discussing, I was testing again in the morning, time optimization always works in MQL5, the result depends on the number of loops, well which test was called first - I won't test it again, it's a waste of time

 
Igor Makanu:

there should be no if() in loops , previously the loop was executed by CX case

I'm not discussing, I was testing again in the morning, time optimization always works in MQL5, the result depends on the number of loops, well, which test was called first, I won't test it again, it's a waste of time

.... You need to watch your posts)))) the post above refers to the post that suggested that the ArraySize operator checks for overruns (THIS is your if) and it's by adding it to the body that you really check, and this is the only correct way.

And the difference from running the first one is only in your tests)

 
Alexandr Andreev:

And the only difference from running the first one is in your tests)

Give me your test, let's see.

although... No need, I'm participating in the discussion on automatism, you like it, I'm of a different opinion about using ArraySize() in the loop termination condition

 

.ex5 dimensions

void OnStart() // размер 12 272 байт
{
   int arr[];
   ArrayResize(arr, 100);
   ArrayInitialize(arr, 1);
   int sum = 0;
   for(int i = ArraySize(arr) - 1; i >= 0; i--)
   {
      sum += arr[i];
   }
   printf("sum = %i", sum);//sum = 100
}
//+------------------------------------------------------------------+
void OnStart() // размер 11 860 байт
{
   int arr[];
   ArrayResize(arr, 100);
   ArrayInitialize(arr, 1);
   int sum = 0;
   for(int i = 0; i < ArraySize(arr) - 1; i++)
   {
      sum += arr[i];
   }
   printf("sum = %i", sum);//sum = 100
}
//+------------------------------------------------------------------+
void OnStart() // размер  12 174 байт
{
   int arr[];
   ArrayResize(arr, 100);
   ArrayInitialize(arr, 1);
   int sum = 0;
   for(int i = 0, sz = ArraySize(arr); i < sz; i++)
   {
      sum += arr[i];
   }
   printf("sum = %i", sum);//sum = 100
}
 
Who knows other than the compiler makers? Maybe ArraySize() works just like a variable reference. It seems possible.
 
Dmitry Fedoseev:
And who knows but creators of the compiler? Maybe ArraySize() works just like addressing a variable. It seems possible.
void OnStart()
  {
   int mas[];  
   int size=1000000000;
   ArrayResize(mas,size); 
   int r2=0; 
   int tr=0;  
    int num_steps=ArraySize(mas); 
    double step = 1.0/(double)num_steps;
    
     int v=size;
    ulong t1 = GetMicrosecondCount();
    
  // for(ulong z=0; z<max; z++)
  
   int sizem=Size(mas);
     {
      for(int i=0; i<sizem; i++)
        { 
        r2+=sizem;
        r2|=sizem; 
        }
     } 
   ulong t2=GetMicrosecondCount(); 
     {
      for(int i=0; i<Size(mas); i++)
        {  
        r2+=Size(mas);
        r2|=Size(mas); 
        } 
     }  
   ulong t3=GetMicrosecondCount();
   
  Print(t2-t1," ",t3-t2," ",r2) ; 
  }
 
int Size(int &mas[]){return Size2(mas);} 
int Size2(int &mas[]){return Size3(mas);} 
int Size3(int &mas[]){return ArraySize(mas);} 

Please note that here the test between the function that calls the function that calls ArraySize and the speed is the same, what to access just a variable. Because the compiler just unfolds them

ArraySize

of using ArraySize() in the loop termination condition


and there is no difference from rearranging
Документация по MQL5: Основы языка / Функции / Вызов функции
Документация по MQL5: Основы языка / Функции / Вызов функции
  • www.mql5.com
Если некоторое имя, которое не было описано ранее, появляется в выражении и за ним следует левая круглая скобка, то оно по контексту считается именем некоторой функции. Аргументы (формальные параметры) передаются по значению, т. е. каждое выражение x1, . . . , xn вычисляется и значение передается функции. Порядок вычисления выражений и порядок...
 

another test from the_bald....

Why do you test your creation once?

test it at least ten times to see what happens

wrapped in external loop code, result:

HQ 0 15:26:55.230 tst (EURUSD,H1) 558620 543908 -512

RO 0 15:28:08.672 tst (EURUSD,H1) 544176 543129 -512

EF 0 15:28:09.759 tst (EURUSD,H1) 544139 543144 -512

RM 0 15:28:10.847 tst (EURUSD,H1) 544174 543436 -512

GD 0 15:28:11.934 tst (EURUSD,H1) 543668 543531 -512

CR 0 15:28:13.021 tst (EURUSD,H1) 543413 543097 -512

JI 0 15:28:14.107 tst (EURUSD,H1) 543046 543218 -512

HP 0 15:28:15.194 tst (EURUSD,H1) 543337 543469 -512

PO 0 15:28:16.282 tst (EURUSD,H1) 543602 544455 -512

KE 0 15:28:17.369 tst (EURUSD,H1) 543253 543197 -512

CL 0 15:28:18.457 tst (EURUSD,H1) 544199 543664 -512

I will not rearrange tested cycles, I got bored with them - the code size above, it means good optimization, maybe with the code analyzer, last year I was surprised, in iCustom optimization for MQL4 - 4 calls of 4= indicator buffers are replaced with one call , there was a topic somewhere, again about efficiency

in general, Metacquotes did a good job on analyzing type codes from users, i.e. the compiler will fix most of the users' stuff by itself... cool, imho!

 

Sorry, I could be wrong. I haven't read all of it. Only the first page. The impression is the usual. Someone asks a specific question. And then the flooders come swooping in.

Sorry again, is this really a developer's forum ?????

 
Сергей Таболин:

Sorry, I could be wrong. I haven't read all of it. Only the first page. The impression is the usual. Someone asks a specific question. And then the flooders come swooping in.

Sorry again, is this really a developer forum ?????

Wrong, other questions were raised there too, different from TC's. And understanding the principles of compilation sometimes helps.