Is <11 faster than <=10? - page 5

 
Amir Yacoby:
  It's just a false question

How would you know the answer if you never investigated yourself?

 
William Roeder:
#40 Maximum of 4? I answered OP in #1. :)
Actually your answer was misleading as you talked about integer which is irrelevant on this topic. :-D
 
Alain Verleyen: Actually your answer was misleading as you talked about integer which is irrelevant on this topic. :-D
  1. Actually OP didn't specify a data type. You all have been assuming.
  2. If it is a double then we can reference an 11 page thread and continue that here.
              Which is faster - Floating-Point or Integer arithmetic? - Expert Advisors and Automated Trading - MQL5 programming forum - Page 11
 

Easier than installing "Wine MT4" on Linux; which requires discovering you need a MicroSoft Windows PC/MicroSoft Windows Virtualization Capable PC so you can first install it there then copy it over and cross your fingers it still works after probably first having tried a couple other more intuitive methods.

https://www.youtube.com/watch?v=fKU5_zjmEg0

 
Seng Joo Thio:

Ha! Apparently MQL5 compiler is smarter than MQL4. So I've modified my test code to this for MT5:

And got these results:

So, as before, there is no clear winner. Time fluctuations, given their magnitude of <100 milliseconds for 2147483647 operations (inclusive of 2 x MathRand on top of < or <=), are likely due to pc load.

Seng Joo Thio,  

You actually did a good job here.

All of us know that whichever is faster is actually negligible. But since some of us are really interested to know which is faster, so I thought of changing a bit of your code.

I didn't use random as it will give random results to compare. Also in "<=", a false result is slower than true, so random won't give a concrete finding. It maybe the fact that we are looking for once we run the code.

The results are too long to post here so feel free to run if you are interested to know. if you run the code, if possible, please do not run other apps in the background so will get a more accurate results.

Here it is...

ulong iStart = 0, iStop = 0;
bool bResult;

void OnTick()
  {  
   int total = 0;
   double ave = 0;
   for (int i=0; i<100; i++)
   {
      int T1 = TestL(), T2 = TestLT();
      total += (T1 - T2);
      ave = total/(i+1);
      PrintFormat("Run %3d:    (<) %8d      (<=) %8d     (Diff) %8d       (Total) %8d       (Average) %8f", i+1, T1, T2, T1-T2,total, ave);      
   }
   
   string result = "********* With 100 cycles, "; 
   if(ave<0) result += "(<) is faster than (<=)";
   else result += "(<=) is faster than (<)";
   
   Print(result);
  
  }

int TestL()
{   
   int max1 = INT_MAX-1;
   iStart = GetMicrosecondCount();
   for (int i=0; i<INT_MAX; i++)
      bResult = max1<i;
   iStop = GetMicrosecondCount();
   return int(iStop-iStart);
}

int TestLT()
{
   int max1 = INT_MAX-1;
   iStart = GetMicrosecondCount();
   for (int i=0; i<=max1; i++)
      bResult = max1<=i;
   iStop = GetMicrosecondCount();
   return int(iStop-iStart);
}
 
Joel Protusada:

 But since some of us are really interested to know which is faster,..


Why do you find it hard to understand, you will never find who is faster, because they are exactly the same.

Now, take your test code and run both parts as '<' - and tell me which is faster.
I know they are almost the same, but please run it and tell me who is faster, the first '<' or the second '<'.

Your code should get a clear winner, even if they are almost the same, I want to know.

 
Amir Yacoby:

Why do you find it hard to understand, you will never find who is faster, because they are exactly the same.

Now, take your test code and run both parts as '<' - and tell me which is faster.
I know they are almost the same, but please run it and tell me who is faster, the first '<' or the second '<'.

Your code should get a clear winner, even if they are almost the same, I want to know.

How would you know the answer if you never investigated yourself?

 
Joel Protusada:

How would you know the answer if you never investigated yourself?

How do you know which is faster, the first '<' or the second '<' without running a test? Please run and tell me.
 
Amir Yacoby:
How do you know which is faster, the first '<' or the second '<' without running a test? Please run and tell 

I wouldn't post the code if I haven't tested it. It says over and over that "<" is faster than "<=".  It just too long to post all the 100 cycles in here. You should test it yourself so you will know the answer. From the very beginning I never told anyone here that they are wrong. I just posted the old-school knowledge and facts that I know that I have learned throughout the years. I just posted my investigation. Please just post your own finding if you have one. Thanks.