Performance test: MQL4 vs. MQL5

 

I was curious about the speed of mql4 compared to mql5, so I did a little test. I implemented a simple prime searching algorithm and ran in MT4 and MT5.

Code in MQL4:

int filehandle, i, d;
double x;

int start() {
   Print(TimeLocal());
   filehandle=FileOpen("primes.txt",FILE_WRITE);
   for (i = 1; i <= 10000000; i++) {
           if(i % 2 != 1) { continue; }
           d = 3; 
           x = MathSqrt(i); 
           while(i % d != 0 && d < x) {
                   d += 2;
           }
           if(((i % d == 0 && i != d) * 1) == 0) {
         FileSeek(filehandle,0,SEEK_END);
         FileWrite(filehandle,i);
           }
   }
   FileClose(filehandle);
   Print(TimeLocal());   
   return(0);
}

For MT5 only 1 line need to be modified:

int start() {

to:

int OnStart() {

Five runs in MT4:

2011.10.22 18:08:40     primetest EURUSD,H1: 1319306920
2011.10.22 18:08:16     primetest EURUSD,H1: 1319306896
2011.10.22 18:08:16     primetest EURUSD,H1: loaded successfully
2011.10.22 18:08:13     primetest EURUSD,H1: 1319306893
2011.10.22 18:07:49     primetest EURUSD,H1: 1319306869
2011.10.22 18:07:49     primetest EURUSD,H1: loaded successfully
2011.10.22 18:07:38     primetest EURUSD,H1: 1319306858
2011.10.22 18:07:14     primetest EURUSD,H1: 1319306834
2011.10.22 18:07:14     primetest EURUSD,H1: loaded successfully
2011.10.22 18:07:10     primetest EURUSD,H1: 1319306830
2011.10.22 18:06:46     primetest EURUSD,H1: 1319306806
2011.10.22 18:06:46     primetest EURUSD,H1: loaded successfully
2011.10.22 18:06:42     primetest EURUSD,H1: 1319306802
2011.10.22 18:06:18     primetest EURUSD,H1: 1319306778
2011.10.22 18:06:18     primetest EURUSD,H1: loaded successfully

Five runs in MT5:

2011.10.22 18:11:51     primetest (EURUSD,M1)   2011.10.22 18:11:51
2011.10.22 18:11:43     primetest (EURUSD,M1)   2011.10.22 18:11:43

2011.10.22 18:11:38     primetest (EURUSD,M1)   2011.10.22 18:11:38
2011.10.22 18:11:29     primetest (EURUSD,M1)   2011.10.22 18:11:29

2011.10.22 18:11:28     primetest (EURUSD,M1)   2011.10.22 18:11:28
2011.10.22 18:11:19     primetest (EURUSD,M1)   2011.10.22 18:11:19

2011.10.22 18:11:18     primetest (EURUSD,M1)   2011.10.22 18:11:18
2011.10.22 18:11:09     primetest (EURUSD,M1)   2011.10.22 18:11:09

2011.10.22 18:11:06     primetest (EURUSD,M1)   2011.10.22 18:11:06
2011.10.22 18:10:57     primetest (EURUSD,M1)   2011.10.22 18:10:57

You can see that the difference is HUGE: in MT4 the script needs 24 seconds, while in MT5 it only needs 9 seconds! I was very much surprised, I did not imagine so much difference in performance, but I like that. Too bad there is no live MT5 broker.

 
Too bad there is no live MT5 broker. There Is.
 
balazs321:

I was curious about the speed of mql4 compared to mql5, so I did a little test. I implemented a simple prime searching algorithm and ran in MT4 and MT5.

Code in MQL4:

For MT5 only 1 line need to be modified:

to:

Five runs in MT4:

Five runs in MT5:

You can see that the difference is HUGE: in MT4 the script needs 24 seconds, while in MT5 it only needs 9 seconds! I was very much surprised, I did not imagine so much difference in performance, but I like that. Too bad there is no live MT5 broker.

That is just the OnStart() only for scripts. Wait till you see OnTick(), OnTrade(), OnTimer(),etc, working hand in hand - you'll be amazed not just speed, but entire EA execution. also, the mt5 tester/optimization, just wow.

There are rumours going round that if you have mt4 live account and will like an mt5 live you can request for it, but you have to sign some forms. I don't know how true.

 
ubzen:
Too bad there is no live MT5 broker. There Is.

Okay, tell me!
 
Here.
 

maybe the most of time is used for file operations.

Why calculate time include file operations ?

try compare without file operation, 32 mode or 64 mode .

 
Well, I think the relative difference would not change even without the file operations. But you can try it and post your results :)
 

Here are some measured times on an i7-2600:

times with file I/O - times without file I/O

MQL4 18 sec 12 sec

MQL5 9.3 sec 4.3 sec

VB6 5.3 sec 4.9 sec

Delphi 4.1 sec 3.8 sec

 
clyx58:

Here are some measured times on an i7-2600:

times with file I/O - times without file I/O

MQL4 18 sec 12 sec

MQL5 9.3 sec 4.3 sec

VB6 5.3 sec 4.9 sec

Delphi 4.1 sec 3.8 sec


(VB).NET 14.5 sec
 
That's cool, thanks!
 
Does MT5 parallel task optimization? I read on some forum that optimization is much quicker in MT5. On my PC (quad core I7), optimization tasks hardly tax the CPU at all on MT4. Optimization would be an ideal candidate for parallel execution or multiple threads. I have been thinking of starting multiple instances of MT4 to share the optimization load - has anybody done this before and is it a viable solution (just asking before I spend time if somebody has done this already to no avail)?
Reason: