Time optimalization MQL code

Back to topics list To post a new topic, please log in or register
avatar
193
endy5 2015.02.04 11:14
 

 

Information to all

 

Hi guys,

I deal with now time optimalization mql code. I have found that preprocesor mql language test all boolean conditions even though the result is clear already after some condition.

Example: When 5 conditions type boolean and your code is:

if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ...

   if cond1 is false -> is clearly that result all conditions is false so. But MQL preprocesor testing all conditions. If "cond.." is example function with return boolean type, can it calcul operation inside this function more time - unnecessarily!

Demonstrativ code:

 My question - Does have mql preprocesor some direktive for it? I would like write code as if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ... and at the same time I need time optimalization code.

Thank you. 

#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  { // version time optimization
    bool cond1=false;
    uint timer=GetTickCount();
    if ( cond1)
      if(Cond2()) {}
    Alert("Version quickly: Working time is: ",GetTickCount()-timer,"ms");
   
   // version time slowly
    cond1=false;
    timer=GetTickCount();
    if ( cond1& Cond2()) {}
    Alert("Version slowly: Working time is: ",GetTickCount()-timer,"ms");
   

  }
//+------------------------------------------------------------------+
bool Cond2()
{ int i=0;
  while (i<10002220)
  { 
    i++;
  }
  return (false);
}
avatar
1109
Ovo 2015.02.04 11:31 #
 
endy5:

 

Information to all

 

Hi guys,

I deal with now time optimalization mql code. I have found that preprocesor mql language test all boolean conditions even though the result is clear already after some condition.

Example: When 5 conditions type boolean and your code is:

if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ...

   if cond1 is false -> is clearly that result all conditions is false so. But MQL preprocesor testing all conditions. If "cond.." is example function with return boolean type, can it calcul operation inside this function more time - unnecessarily!

Demonstrativ code:

 My question - Does have mql preprocesor some direktive for it? I would like write code as if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ... and at the same time I need time optimalization code.

Thank you. 

What do you mean by the "preprocessor test all boolean conditions" ? Anyway, during runtime the processing follows the C++ standards for 600+ code (with strict directive).

 

avatar
193
endy5 2015.02.04 13:47 #
 

If I have conditions: 1.) false 2.)true 3.) true 4.) true and 5.) true

and code if ( cond1 && cond2 && cond3 && cond4 && cond5 )  {...}

process running and testing all conditions although result is clearly after test the first condition.

avatar
1211
deysmacro 2015.02.04 14:18 #
 
Have you tried it at normal charts? The condition you are saying should stop immediately if cond1 is false.
avatar
12983
WHRoeder 2015.02.04 15:08 #
 
endy5:

 if  ( cond1 & cond2 & cond3 & cond4 & cond5 ) ...

   if cond1 is false -> is clearly that result all conditions is false so. But MQL preprocesor testing all conditions. If "cond.." is example function with return boolean type, can it calcul operation inside this function more time - unnecessarily!

Is necessary. It has to compute all five because you are computing a bit mask. 1 & 2 & 4 == 0 Bitwise Operations - MQL4 Documentation

Use boolean operators cond1 && cond2 && cond3... Boolean Operations - MQL4 Documentation

the calculation of the expression is terminated when the result of the expression can be precisely estimated.

avatar
193
endy5 2015.02.04 22:45 #
 

Hi WHRoeder,

 I have no doubt that you know more about mql than I do... but my time test code does not endorse what you write:

"the calculation of the expression is terminated when the result of the expression can be precisely estimated."

 

For my basic time test code on top page - quickly version time test is 0ms, slowly version about 10ms. I repeted test many times. It is fact.

avatar
12983
WHRoeder 2015.02.04 23:11 #
 
What I wrote and what you initially wrote are different. Show the actual code.
avatar
108
eddie 2015.02.04 23:22 #
 

Hi endy5!

You can`t compare your 2 versions.

If you are computing a BIT MASK, you can't split the Operation into two ore more lines. If you do so, you'll get a different result.


I think you will do a LOGICAL Operation (your variables are bool and initalized with false). Therfore you have to use && as Boolean Operator.

avatar
193
endy5 2015.02.05 08:18 #
 

Hi.

I am sorry. Very stupid my inattention!  You have the right!

Perhaps it would be better to delete the whole thread, because it is just wrong. Does not have any information for others users.

I am sorry.  

Back to topics list  

To add comments, please log in or register