Download MetaTrader 5
To add comments, please log in or register
Do you want to know about the MQL5.community development? Have a look at the Wall!
Carl Schreiber
5932
Carl Schreiber 2015.01.17 09:04 

Hi,

I just wrote a little script for a speed test:

//+------------------------------------------------------------------+
//|                                                    SpeedTest.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
#define Pow2(a) ((a)*(a))

void OnStart()
  {
//---
   string c1, c2;
   uint end, beg = GetTickCount();
   double x,p = M_PI;
   int  i,y,d = Digits,loops = 100000000; //EMPTY_VALUE;
   for(i=0;i<loops;i++) {
      x = MathPow(p*M_LN2,2);
      y = (int)MathPow((double)d,2);
   } 
   end = GetTickCount()-beg;
   c1 = StringConcatenate("MathPow( (x*y),2 ) => ",DoubleToString((double)end/1000.0,3)," sec" );

   beg = GetTickCount();
   for(i=0;i<loops;i++) {
      x = Pow2( (p*M_LN2) );
      y = Pow2((d));
   } 
   end = GetTickCount()-beg;
   c2 = StringConcatenate("Pow2( (x*y) ) => ",DoubleToString((double)end/1000.0,3)," sec" );
   Comment("Loops: ",(string)loops,"\n",c1,"\n",c2);
   Print("Loops: ",(string)loops,"   ",c1,"   ",c2);
  }
//+------------------------------------------------------------------+


And this is the result:

2015.01.17 10:05:19.913	SpeedTest EURUSD,M1: Loops: 100000000   MathPow( (x*y),2 ) => 15.850 sec   Pow2( (x*y) ) => 1.139 sec

Alain Verleyen
Moderator
28520
Alain Verleyen 2015.01.17 09:55  
gooly:

Hi,

I just wrote a little script for a speed test:


And this is the result:



What's your conclusion ?

That seems perfectly normal to me as MathPow is a generic solution, not a "power 2" function.

EDIT: Here is my results.

2015.01.17 10:57:34.256    66392 EURUSD,M15: Loops: 100000000   MathPow( (x*y),2 ) => 12.824 sec   Pow2( (x*y) ) => 0.343 sec

rod178
276
rod178 2015.01.17 13:03  
gooly:

Hi,

I just wrote a little script for a speed test:


And this is the result:



 

My result 

 EURUSD,M15: Loops: 100000000   MathPow( (x*y),2 ) => 11.294 sec   Pow2( (x*y) ) => 0.203 sec 

 Likewise - and then..?

Carl Schreiber
5932
Carl Schreiber 2015.01.17 13:24  
angevoyageur:

What's your conclusion ?

That seems perfectly normal to me as MathPow is a generic solution, not a "power 2" function.

EDIT: Here is my results.

2015.01.17 10:57:34.256    66392 EURUSD,M15: Loops: 100000000   MathPow( (x*y),2 ) => 12.824 sec   Pow2( (x*y) ) => 0.343 sec


Well on one hand of course I am not surprised on the other hand one can think that build in functions are coded in a way that they in the end are faster or equivalent to 'user functions' and last but not least I would not have expected that MathPow(..) is 42 times slower than Pow2()!
Alain Verleyen
Moderator
28520
Alain Verleyen 2015.01.17 17:55  
gooly:
Well on one hand of course I am not surprised on the other hand one can think that build in functions are coded in a way that they in the end are faster or equivalent to 'user functions' and last but not least I would not have expected that MathPow(..) is 42 times slower than Pow2()!

Can you code it in C/C++ using pow() function and compare the results ? I am not at my main computer and don't have a C compiler installed.

I doubt it's an mql4 issue, as they probably use the underlying C function.

Carl Schreiber
5932
Carl Schreiber 2015.01.17 20:21  
angevoyageur:

Can you code it in C/C++ using pow() function and compare the results ? I am not at my main computer and don't have a C compiler installed.

I doubt it's an mql4 issue, as they probably use the underlying C function.

Sorry no, I have neither a C nor C++ compile installed.

But it is interesting that on my Laptop (Win7 64, Intel Core2 Extreme Q9300 @ 2.53 GHz) compared to your results the MathPow-results are somewhat similar (15.850 sec) to yours (~12 sec) while your Pow2-execution is about 3 times faster than mine!

Why is MatPow() not equivalently faster on your pc (I guess really fast pc) than on my 8 years old laptop?

whroeder1
13597
whroeder1 2015.01.17 21:00  
You are not comparing x^2 vs x*x. You are comparing x^y where y happens to be 2.00000. Big difference.
/
To add comments, please log in or register