Testing the new MQL5 compiler for x64 platforms - 2 to 10 times faster calculations!

 

As we promised earlier, we are releasing a new MQL5 compiler optimized for the 64-bit version of MetaTrader 5.

We have kept full compatibility of the generated code both for 32-bit versions of the terminal and for older versions of the terminals.

You can already upgrade to MetaTrader 5 build 1108 with its new functionality on our MetaQuotes-Demo server. In order to enable the new optimizing compiler, add the Optimize=1 key to [Experts] in metaeditor.ini:

[Experts]
Author=Copyright 2014, MetaQuotes Software Corp.
Address=http://www.mql5.com
Optimize=1


To test the performance of MQL4, MQL5 and C++ compilers, we have used standard compiler tests. All source files are attached together with Excel spreadsheet, so everyone can double-check it.

For now let's have a look at the test results in the following environment:

  • Intel Xeon E5-2687W v3 @3.10 Ghz, 20 cores, 32 Gb DDR4 2100
  • MQL4 on MetaTrader 4 build 794
  • MQL5 on MetaTrader 5 build 1111 x64, normal mode
  • MQL5 on MetaTrader 5 build 1111 x64, new compiler, Optimize=1 mode
  • C++ with Visual Studio 2012 Update 4, x64 code, maximum optimization
  • Time in milliseconds, the less the better

TestMT4 794MT5 1111 x64
MT5 1111 NewC++ x64Comment by
TestAckermann 3718 3109 0 0 Perfect, the two compilers were able to optimise the compilation calculations by throwing out all the code
TestArrays 15063 2531 203 31 There is still room for improvement
TestBubbleSort 10609 2484 656 860 Surprisingly, MQL5 has pulled ahead in the bubble sorting
TestCall 922 891 0 0 Perfect, the two compilers were able to optimise the compilation calculations by throwing out all the code
TestFibo 2547 1187 0 0 Perfect, the two compilers were able to optimise the compilation calculations by throwing out all the code
TestMatrix 15375 4359 422 281 There is still room for improvement
TestMoments 5719 4323 4078 0 Perhaps, by including more optimization methods, we will be able to trash the code like MSVC
TestNestedLoop 6219 6141 0 0 Perfect, the two compilers were able to optimise the compilation calculations by throwing out all the code
TestPiCalculated 5047 3500 1875 1859 Nose to nose with MSVC
TestRandom 2375 1828 468 438 Almost as good as MSVC
TestSieve 13578 4031 875 515 Close
TestString 187 218 422 266 Optimize and overtake MSVC, this is a temporary flop due to insufficient optimization
TestStrPrep 3938 3328 1703 1875 Faster than MSVC
TestStrRev 4000 3141 2719 438 We have to figure it out.
TestStrSum 5344 2812 2844 0 Possibly, by adding more optimization methods, we will be able to eliminate the code like in MSVC


To see the detailed chart, please click on it.


What are the conclusions:

  1. MQL4 is seriously losing to MQL5 even based on one compiler

    MQL5 is faster than MQL4 from tens of percents up to several times. The reason is in the execution environment and 32 bits. MetaTrader 5 has a much more efficient and constantly developing runtime.

  2. The new 64-bit MQL5 compiler is 2 to 10 times faster than the current MQL5

    The development of the new compiler took a long time, but the gains were amazing. There are some issues with optimization of string operations, but we will try to speed them up as well.

  3. The new compiler is very close to the quality and speed of the Visual Studio 2012 x64 compiler.

    We haven't activated all the optimization methods yet since we are still testing them. Therefore the results will continue to improve.


What does it give to traders?

The ability to do more calculations in the same amount of time and less thinking about switching to a DLL. This is especially important for those who do the heavy maths.

 

Well done!

 

Professionals in their field!

Thank you!

 

Also in addition - the next release by May 20 will most likely have a debugger available on historical data.

We will be showing it at the iFX Expo on May 26-28.

iFX EXPO International 2015
  • iFX EXPO
  • www.ifxexpo.com
Booth 01 Get the world’s fastest HTML5 chart for mobile & desktop, and the highest user-rated mobile apps - with or without trading. Founded in 1998, NetDania pioneered streaming price technology, and have since delivered solutions to global Tier-1 banks, brokers, currency managers, and analysts. With a strong position within corporate FX and...
 

Renat Fatkhullin:

  1. The new 64-bit MQL5 compiler is 2 to 10 times faster than the current MQL5 compiler.

    The development of the new compiler has taken a long time, but the gains have been amazing. There are some issues with optimization of string operations, but we will try to speed them up as well.

  2. The new compiler is very close to the quality and speed of the Visual Studio 2012 x64 compiler.

    We haven't activated all the optimization methods yet since we are still testing them. Therefore, the results will continue to improve.


In addition, a debugger on historical data will most likely be available in the next release by the 20th of May.

We will demonstrate it at the iFX Expo on May 26-28.

Very welcome news, thank you!
 
Thank you, I wish you further success!
 
Renat Fatkhullin:

The new compiler comes very close to the quality and speed of the Visual Studio 2012 x64 compiler

We haven't activated all the optimization methods yet since we are still testing them. That is why the results will continue to improve.

Good news ! Well done !

Renat Fatkhullin:

You may perform more calculations at the same time and think less about switching to DLL. This is especially important for those who do heavy maths.


Yes, I really can't think of any more tasks where external DLLs are needed.


Renat Fatkhullin:

Also in addition - the next release by May 20th will most likely have a debugger available on historical data.

This is really the most useful feature. Thank you very much indeed.

Personally I have only one question - pointers to arrays. For private arrays the problem is solved by wrapping an array into a class.

But for arrays passed into OnCalculate() function I have to copy the data into internal buffers each time, and only then pass pointers into analyzer objects and handlers. Once I've tried to pass pointers using memcpy, but somehow the speed was almost the same, and in my opinion, such "tricks" should not be applied.

Perhaps the possibility of using reference type would be more acceptable. In general, the task is to access array elements without copying them.

 
George Merts:

Yes, I can't really think of any more tasks where external DLLs are needed.

For example, inter-terminal communications.
 
I tried to compile one of my robots with optimization.
It turned out that assigning of the deviation input parameter to the deviation field of MqlTradeRequest structure instance leads to code generation error.
Hypothetical example (everything else has been removed):
sinput ulong deviation = 100;
int OnInit()
  {
        MqlTradeRequest request =
        {
                0
        };
        request.deviation = deviation;
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
I get"code generation error 1 1".

If you just assign "100":

int OnInit()
  {
        MqlTradeRequest request =
        {
                0
        };
        request.deviation = 100;
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }

...then the compilation will go through without errors. Note, I have AMD Athlon II X4 645, 3.1 GHz processor. Maybe it's important (just this week MQL4 with servicedesk have been catching some bug on AMD).

My compiler doesn't complain about anything else.

 
Thank you for reporting the error - we will fix it.