2 questions regarding mql speed.

 

2 questions, just as much curiosity as anything else.

a) which reads faster.

      worsTics[0]=worsTics[1]=worsTics[2]=worsTics[3]=worsTics[4]=worsTics[5]=worsTics[6]=worsTics[7]=worsTics[8]=worsTics[9]=worsTics[10]=worsTics[11]=0;

// OR

        for(int i = 0; i <12; ++i)
                worsTics[i];

b) again: which reads faster.

bool quest? dothis: orthat;

// OR

if(question)
        dothis;
else
        dothat;
 
Revo Trades:

a) which reads faster.

This

for(int i = 0; i <12; ++i)
   worsTics[i] = 0;

will most likely be optimized by the compiler


Revo Trades:
b) again: which reads faster.

I think it wouldn't be logical if equivalent entries were calculated at different speeds

Ternary Operator ?:

double true_range = (High==Low)?0:(Close-Open)/(High-Low);

This entry is equivalent to the following:
double true_range;
if(High==Low)true_range=0;               // if High and Low are equal
else true_range=(Close-Open)/(High-Low); // if the range is not null

 
They just express it in different ways, it may be the same thing to the computer.

If you want to speed up the EA, you should reduce the frequency of receiving ticks, or store the same function called several times in the same variable.

Reducing the number of function calls and storing functions in variables will help speed up the EA operation and reduce CPU and memory usage.
 
Revo Trades:
a) which reads faster.

Even if we imagine that the loop would run a little slower (although I think it wouldn't). It's better to use a loop anyway. Would you agree to make your code unusable for edits and maintenance in order to save half a nanosecond of CPU time (with this approach, your code will definitely become one-time only)? It's cheaper to upgrade hardware than to spend a huge amount of time trying to make changes to one-time code.

In addition, such calculations are usually performed during initialization, and ready-made values are used during operation.

 
Hong Yi Li #:
They just express it in different ways, it may be the same thing to the computer.

If you want to speed up the EA, you should reduce the frequency of receiving ticks, or store the same function called several times in the same variable.

Reducing the number of function calls and storing functions in variables will help speed up the EA operation and reduce CPU and memory usage.

thanks for the reminder. I will see about decreasing the frequency that the aforementioned are used, rather than be further concerned with the specific lines.

 
Vladislav Boyko #:

Even if we imagine that the loop would run a little slower (although I think it wouldn't). It's better to use a loop anyway. Would you agree to make your code unusable for edits and maintenance in order to save half a nanosecond of CPU time (with this approach, your code will definitely become one-time only)? It's cheaper to upgrade hardware than to spend a huge amount of time trying to make changes to one-time code.

In addition, such calculations are usually performed during initialization, and ready-made values are used during operation.

totally agree. thanks.

 
Revo Trades: a) which reads faster.
Do not assume. Always test. Sometimes you get surprised.
          Which is faster - Floating-Point or Integer arithmetic? - Expert Advisors and Automated Trading - MQL5 programming forum - Page 11
 
William Roeder #:
Do not assume. Always test. Sometimes you get surprised.
          Which is faster - Floating-Point or Integer arithmetic? - Expert Advisors and Automated Trading - MQL5 programming forum - Page 11

interesting; to say the least. I am curious about the lines i demonstrated above, if either case is faster than the other, but am not desperate enough to spend time to carry out the test. I was hoping that one of the mql gods had done such a test before today. (hint hint). Thanks for the link.

Reason: