Is MQL compiled or interpreted? - page 7

 

This topic is funny I would say. Some people are discussing like experts about something they obviously don't know (and I am not an expert about compiler either).

As clearly explained by Stanislav and the links he provided, mql (4 or 5 doesn't matter) is compiled into native code. There is nothing to discuss, it's a fact, unless you think Renat is lying. Old mql4 which was possible to decompile to source code was entirely an other story, obviously, but it's now totally obsolete.

A compiled code doesn't mean it's mandatory faster or without debugging information (array our range reporting source code line).

mql 4/5 is a managed language, it runs inside MT4/MT5, and it can't allowed to work directly with memory like C++, it has to check every access (how could it know there is an array out of range otherwise), that's why working with arrays is not that fast.I am sure you don't want to crash your trading platform each time you made a small error in your code. That's why you don't have real pointers.

Still the compiler produces native code. They are even preparing their compiler to compile C++ code in a future version.

 
Alain Verleyen:

This topic is funny I would say. Some people are discussing like experts about something they obviously don't know (and I am not an expert about compiler either).

As clearly explained by Stanislav and the links he provided, mql (4 or 5 doesn't matter) is compiled into native code. There is nothing to discuss, it's a fact, unless you think Renat is lying. Old mql4 which was possible to decompile to source code was entirely an other story, obviously, but it's now totally obsolete.

Alain, with all due respect:

You don't understand a text written in plain English. The test shows that MQL5 is about 22 times slower executed than  C++ and that all the talk about pure C++ compilation was hogwash. And even more interesting also the 64bit version (the only MetaTrader version with a supposed native compiler) is NOT relatively faster compared to interpreted MQL (all other MetaTrader versions since more than 12 years).

 
Alain Verleyen:

This topic is funny I would say. Some people are discussing like experts about something they obviously don't know (and I am not an expert about compiler either).

As clearly explained by Stanislav and the links he provided, mql (4 or 5 doesn't matter) is compiled into native code. There is nothing to discuss, it's a fact, unless you think Renat is lying. Old mql4 which was possible to decompile to source code was entirely an other story, obviously, but it's now totally obsolete.

A compiled code doesn't mean it's mandatory faster or without debugging information (array our range reporting source code line).

mql 4/5 is a managed language, it runs inside MT4/MT5, and it can't allowed to work directly with memory like C++, it has to check every access (how could it know there is an array out of range otherwise), that's why working with arrays is not that fast.I am sure you don't want to crash your trading platform each time you made a small error in your code. That's why you don't have real pointers.

Still the compiler produces native code. They are even preparing their compiler to compile C++ code in a future version.

Whatever ...

That is interpreting ...and that was the point of showing the whole thing. Without interpretation the speeds would be comparable (debugger info or not)

All the best

 
alphatrading:

Alain, with all due respect:

You don't understand a text written in plain English. The test shows that MQL5 is about 22 times slower executed than  C++ and that all the talk about pure C++ compilation was hogwash. And even more interesting also the 64bit version (the only MetaTrader version with a supposed native compiler) is NOT relatively faster compared to interpreted MQL (all other MetaTrader versions since more than 12 years).

Mladen test is meaningless. It compares what can't be compared.

  • It's done in profiler mode, which says nothing about the real speed. (Is the DLL profiled ?)
  • It's 32bit when it's clearly stated that only 64bit is completely optimized. (And I can't check it as I don't have MT5 32 bit)
  • He doesn't provide the DLL source code so we can't check if the algorithm is the same or optimized in some way.
  • He doesn't say how it was done, are this on a live chart (I doubt it waited for 3.5 millions live ticks ?) or on historical data.

Anyway, as I said speed and compiler are not necessarily correlated.

About your claims that old mql4 (build 225) as you said is faster than current version, it's just a joke. Please try to prove it, and not with a niche example which will prove nothing.

 
Mladen Rakic:

Whatever ...

That is interpreting ...and that was the point of showing the whole thing. Without interpretation the speeds would be comparable (debugger info or not)

All the best

Alain Verleyen:

Mladen test is meaningless. It compares what can't be compared.

  • It's done in profiler mode, which says nothing about the real speed. (Is the DLL profiled ?)
  • It's 32bit when it's clearly stated that only 64bit is completely optimized. (And I can't check it as I don't have MT5 32 bit)
  • He doesn't provide the DLL source code so we can't check if the algorithm is the same or optimized in some way.
  • He doesn't say how it was done, are this on a live chart (I doubt it waited for 3.5 millions live ticks ?) or on historical data.

Anyway, as I said speed and compiler are not necessarily correlated.

About your claims that old mql4 (build 225) as you said is faster than current version, it's just a joke. Please try to prove it, and not with a niche example which will prove nothing.

Of meaningless test(s) :

  • set the period to 200 on both
  • attach one to the chart (no profiler - live chart).  Count
  • attach the other to the chart (no profiler - live chart).  Count

I explicitly wanted to use something heavy on the CPU for the sake of being able to compare the execution times of native code and "native" code. No other reason. No arrays access times, no fixing, no debugging. But something that can be compared even without the profiler.

With the method described above (the "count-my-fingers" method) you are comparing what CAN be compared. And the ratio will remain the same (unless I, somewhere in my age, forgot to count)

 
Mladen Rakic:

Of meaningless test(s) :

  • set the period to 200 on both
  • attach one to the chart (no profiler - live chart).  Count
  • attach the other to the chart (no profiler - live chart).  Count

I explicitly wanted to use something heavy on the CPU for the sake of being able to compare the execution times of native code and "native" code. No other reason. No arrays access times, no fixing, no debugging. But something that can be compared even without the profiler.

With the method described above (the "count-my-fingers" method) you are comparing what CAN be compared. And the ratio will remain the same (unless I, somewhere in my age, forgot to count)

Can't test anything as you provide 32-bit version only. Can you provide the DLL source code ?

Don't you think an indicator's buffer is a dynamic array ?

Try to add index checking on each access into your DLL code, then it will be comparable.

 
Alain Verleyen:

Can't test anything as you provide 32-bit version only. Can you provide the DLL source code ?

Don't you think an indicator's buffer is a dynamic array ?

Try to add index checking on each access into your DLL code, then it will be comparable.

As of arrays (since the wrong dimension is checked at compile time already) :there are two things (and only two things) that need to be checked :

  • is the index less than 0
  • is the index exceeding the size of the array

As of the source : feel free to use and test it (attached it) - as I have told : no secret algo, essentially the same thing, just in real native compiled form. Used the simplest visual studio community edition for compilation


Files:
iDwma.zip  1 kb
 
Mladen Rakic:

As of arrays (since the wrong dimension is checked at compile time already) :there are two things (and only two things) that need to be checked :

  • is the index less than 0
  • is the index exceeding the size of the array

As of the source : feel free to use and test it (attached it) - as I have told : no secret algo, essentially the same thing, just in real native compiled form. Used the simplest visual studio community edition for compilation


Thanks.
 

So I made some work on this, on MT5-64 bit (build 1940). and I got some surprising results if you think mql is interpreted.

2018.11.03 10:48:33.067    IDWMA (EURUSD,M1)    IDWMA Original mql5 (14-PRICE_CLOSE) : 5016172 bars processed in 3106384 µs.
2018.11.03 10:48:53.892    idwma_2 (EURUSD,M1)    idwma with DLL (14-PRICE_CLOSE) : 5016172 bars processed in 4537182 µs.
2018.11.03 10:49:05.122    idwma_noDLL (EURUSD,M1)    idwma NO dll (pure mql5). (14-PRICE_CLOSE) : 5016172 bars processed in 3010602 µs.

IDWMA is the original indicator, code posted in Codebase. idwma_2 is Mladen version using a DLL. idwma_noDLL is the exact same logic of Mladen version but with mql5 pure code. My computer is not fast.

This is executed on a live chart, no debug, no profiler, MT5 "Bars max in chart" set to Unlimited. DLL version is the slowest with a low period (14).

Period 50. Original IDWMA still faster, but not much difference actually.

2018.11.03 11:33:10.103    idwma_noDLL (EURUSD,M1)    idwma NO dll (pure mql5). (50-PRICE_CLOSE) : 5016172 bars processed in 34510017 µs.
2018.11.03 11:35:07.770    idwma_2 (EURUSD,M1)    idwma with DLL (50-PRICE_CLOSE) : 5016172 bars processed in 38321194 µs.
2018.11.03 11:36:07.601    IDWMA (EURUSD,M1)    IDWMA Original mql5 (50-PRICE_CLOSE) : 5016172 bars processed in 29994012 µs.

Period 200. Original IDWMA still a little faster.

2018.11.03 11:46:30.856    idwma_2 (EURUSD,M1)    idwma with DLL (200-PRICE_CLOSE) : 5016172 bars processed in 507378503 µs.
2018.11.03 11:55:52.677    IDWMA (EURUSD,M1)    IDWMA Original mql5 (200-PRICE_CLOSE) : 5016172 bars processed in 464595404 µs.
2018.11.03 12:07:25.857    idwma_noDLL (EURUSD,M1)    idwma NO dll (pure mql5). (200-PRICE_CLOSE) : 5016172 bars processed in 533547635 µs.

I ran the tests without the computer doing anything else. Of course it's still not a complete scientific results. But the conclusion is there is no real difference between the 3 versions.

Files:
 

32 bit terminal- same tests (just 5000 bars but that is enough already)


The only conclusion is that it (the 32 bit version of terminal) is treated as a kind of a "bastard"

Reason: