Which is faster - Floating-Point or Integer arithmetic? - page 6

 
nicholishen:

Is your blood boiling because you just realized that you might have spent all that time doing int optimizations, and now MT5

?

I mean, with these results, int conversion should actually be considered a de-optimization, am I right?

Is my code not a true apples to apples? If it's not please point out the error in my ways!


It changes absolutely nothing whether you spend time optimizing or not. The "error", the "thing" or whatever is reproduced during live sessions.

But yeah it may change the way the ea will act - depending on the context

 
Icham Aidibe:

It changes absolutely nothing whether you spend time optimizing or not. The "error", the "thing" or whatever is reproduced during live sessions.

But yeah it may change the way the ea will act - depending on the context


Context: some here have a hypothesis that converting all doubles to integers will yield a higher performance on MT5. That hypothesis was tested and failed to produce a meaningful result. Therefore, adding the overhead of the arithmetic required to convert a double to an int only increases performance latency (until proven otherwise). If you need to round a double the most efficient method is

double rounded_double = step * round(number / step);

 ...and if you need to compare two doubles for equality the most efficient method (according to edge testing) is 

bool(fabs(num1-num2) < step/10*5);
 
nicholishen:

Context: some here have a hypothesis that converting all doubles to integers will yield a higher performance on MT5. That hypothesis was tested and failed to produce a meaningful result. Therefore, adding the overhead of the arithmetic required to convert a double to an int only increases performance latency (until proven otherwise). If you need to round a double the most efficient method is

 ...and if you need to compare two doubles for equality the most efficient method (according to edge testing) is 


It's not really a solution to convert all doubles to integer. Actually it would be more productive if .... 

 
Fernando Carreiro:

To all involved on this thread, here is a short message and also some advice!

My blood is currently "boiling hot", and I may just start spurting out extremely vile language and breaking the forum rules. So, I am going to try to apply some self-control and abandon the discussion.

To those that may be following it, I now leave to you to decide for yourself and ask that you do your own testing and research and come to your own conclusions.

Regards,
Fernando

Good decision 


 
Alain Verleyen:

Good decision 


Alain, you know mql5 better than anyone... Can you tell me why double performs the same as int on mt5? 
 
Icham Aidibe:

It's not really a solution to convert all doubles to integer. Actually it would be more productive if .... 

You come a bit late to this discussion, please read the thread and don't rely on distorted presentation done by @nicholishen

Converting all doubles to integer is 1 solution, when you have arithmetic operations to do, nothing less, nothing more.

Here the conclusion from the test :

The tests demonstrate that if you don't have arithmetic operations to do, the best solution is :

   if(MathAbs(num1-num2) < _Point / 10.0 * 5)

If you have some arithmetic operations to do, using ints become faster after X operations (X depending of the operations).

   int res =  ((int)round(num1 / _Point) - (int)round(num2 / _Point));
@nicholishen is not happy with that for some mysterious reason, so he started to become mad or something.
 
nicholishen:
Alain, you know mql5 better than anyone... Can you tell me why double performs the same as int on mt5? 

Seriously ? 

 
Alain Verleyen:

You come a bit late to this discussion, please read the thread and don't rely on distorted presentation done by @nicholishen

Converting all doubles to integer is 1 solution, when you have arithmetic operations to do, nothing less, nothing more.

Here the conclusion from the test :

@nicholishen is not happy with that for some mysterious reason, so he started to become mad or something.

I PROVED that doubles and integers perform the exact same with a benchmark. Alain is conveniently ignoring the evidence. 

 
Alain Verleyen:

Seriously ? 


Yes.

In a straight up benchmark of <int> vs <double> (no conversions)...

template<typename T>
T Add(const T num1, const T num2)
{
   return num1+num2;
}

...with (1) arithmetic operation and (1) comparison operation...

if( Add(arrD1[i], arrD2[i]) > 2000. )

...why is <int> NOT faster than<double>?

<int>: 28 ms for 10000000 iterations
<double>: 23 ms for 10000000 iterations
#include <Arrays\ArrayInt.mqh>
#include <Arrays\ArrayDouble.mqh>
void OnStart()
{
//---
   srand(_RandomSeed);
   int iterations = (int)pow(10,7);
   CArrayDouble   arrD1;
   CArrayDouble   arrD2;
   CArrayInt      arrI1;
   CArrayInt      arrI2;
   arrD1.Reserve(iterations);
   arrI1.Reserve(iterations);
   arrD2.Reserve(iterations);
   arrI2.Reserve(iterations);
   
   for(int i=0;i<iterations;i++)
   {
      arrI1.Add(rand()%50000);
      arrI2.Add(rand()%50000);
   }
   for(int i=0;i<iterations;i++)
   {
      arrD1.Add((double)arrI1[i]);
      arrD2.Add((double)arrI2[i]);
   }
   
   ///TESTING INT
   long result=0;
   ulong m = GetMicrosecondCount();
   for(int i=0;i<iterations;i++)
      if(Add(arrI1[i], arrI2[i]) > 2000)
         result++;   
   m=GetMicrosecondCount()-m;
   m/=1000;
   printf("<int>: %d ms for %d iterations",m,iterations);
   printf("result = %d",result);
   
   ///TESTING DOUBLE
   result=0;
   m = GetMicrosecondCount();
   for(int i=0;i<iterations;i++)
      if(Add(arrD1[i], arrD2[i]) > 2000.)
         result++;   
   m=GetMicrosecondCount()-m;
   m/=1000;
   printf("<double>: %d ms for %d iterations",m,iterations);
   printf("result = %d",result);
   
}
//+------------------------------------------------------------------+

template<typename T>
T Add(const T num1, const T num2)
{
   return num1+num2;
}

 
nicholishen:

I PROVED that doubles and integers perform the exact same with a benchmark. Alain is conveniently ignoring the evidence. 

That's not serious. I posted (and Fernando too) the code to run, the results, using arithmetic operations. Using int is way faster, and even more with mql5 than with mql4.

Can you admit that ? If not please say us what is wrong in the posted code.


nicholishen:

Yes.

In a straight up benchmark of <int> vs <double> (no conversions)...

...with (1) arithmetic operation and (1) comparison operation...

...why is <int> NOT faster than<double>?


Checking...

Reason: