Download MetaTrader 5

Testing the new MQL5 compiler for x64 platforms - speed up calculations from 2 to 10 times!

To add comments, please log in or register
Having questions to the author of an article? Discuss them on the Forum!
MetaQuotes Software Corp.
Moderator
181061
MetaQuotes Software Corp. 2015.05.01 22:33 

As was promised before, the new MQL5 compiler optimized for the 64-bit version of MetaTrader 5 is released.

Full compatibility of the generated code has been preserved for the 32-bit versions of the terminal, as well as for the old terminal versions.

On our MetaQuotes-Demo server it is already possible to upgrade to MetaTrader 5 build 1108, which has the new functionality available. To enable the new optimizing compiler mode it is necessary to add Optimize=1 key in the [Experts] section of the metaeditor.ini file:

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

Standart compiler tests were used to test the performance of MQL4, MQL5 and C++ compilers. All source files are attached along with the Excel table of results, so that anyone can double-check himself.

For now see 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++ on Visual Studio 2012 Update 4, x64 code, maximum optimization
  • time in milliseconds, the less - the better

TestMT4 794MT5 1111 x64
MT5 1111 NewC++ x64Comment
 TestAckermann 3718 3109 0 0  Perfect, two compilers managed to optimize calculations at compile time by omitting the entire code
 TestArrays 15063 2531 203 31  It is still possible to improve the result
 TestBubbleSort 10609 2484 656 860  Surprisingly, MQL5 got ahead in bubble sorting
 TestCall 922 891 0 0  Perfect, two compilers managed to optimize calculations at compile time by omitting the entire code
 TestFibo 2547 1187 0 0  Perfect, two compilers managed to optimize calculations at compile time by omitting the entire code
 TestMatrix 15375 4359 422 281  It is still possible to improve the result
 TestMoments 5719 4323 4078 0  Perhaps, by including more optimization methods it would be possible to omit the code like MSVC does
 TestNestedLoop 6219 6141 0 0  Perfect, two compilers managed to optimize calculations at compile time by omitting the entire code
 TestPiCalculated 5047 3500 1875 1859  Head to head with MSVC
 TestRandom 2375 1828 468 438  Almost the same as MSVC
 TestSieve 13578 4031 875 515  Close
 TestString 187 218 422 266  We will optimize and overtake MSVC, this is a temporary failure due to insufficient optimization (didn't get around to that)
 TestStrPrep 3938 3328 1703 1875  Faster than MSVC
 TestStrRev 4000 3141 2719 438  Needs investigation
 TestStrSum 5344 2812 2844 0  Perhaps, by including more optimization methods it would be possible to omit the code like MSVC does


To see the detailed chart, please click on it.


The conclusions:

  1. MQL4 seriously falls behind MQL5, even based on the same compiler

    MQL5 is faster than MQL4 by tens of percents to several times. The reason for the loss is the execution environment and 32 bits. MetaTrader 5 has a much more efficient and constantly evolving execution environment.

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

    The developement of the new compiler has taken a very long time, but the benefit turned out to be amazing. There are still questions to the string operation optimizations, but we will try to speed them up as well.

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

    Not all of the optimization methods have been activated yet, as they still undergo testing. Therefore, the results will improve.


How can traders benefit from that?

The ability to make more calculations in the same time and to think less about switching to DLL. This is especially important for those who deal with heavy math.

Compiler Benchmark Results
  • www.cs.cornell.edu
Group Letter A B C D E F G H C++ Java Compiler size (tokens) Ackermann's function Compile  Run  .obj size File reversal Compile  Run  .obj size Constant folding Compile  Run  .obj size Heapsort Compile  Run  .obj size List operations Compile  Run  .obj size Matrix computations Compile  Run ...
To add comments, please log in or register