Libraries: TesterBenchmark

 

TesterBenchmark:

Measuring the net performance of MetaTrader 4/5 strategy testers.

Author: fxsaber

 

We take the Expert Advisor from the delivery and run it in the tester, getting such performance data

------
OnTesterInit
i = 0 Pass = 0 OnTester = 2.231 s.: Count = 3387955, 1518581.4 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
i = 1 Pass = 1 OnTester = 2.214 s.: Count = 3387955, 1530241.6 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
iMin = 1 Results[iMin] = 2.214 s.
iMax = 0 Results[iMax] = 2.231 s.
Amount = 2 Mean = 2.223 s. - 79.08%
OnTesterDeinit
------
Interval = 5.621 s., Count = 0, 0.0 unit/sec

Now let's run the same Expert Advisor, but using Trade.mqh

------
OnTesterInit
i = 0 Pass = 0 OnTester = 3.330 s.: Count = 3387955, 1017403.9 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
i = 1 Pass = 1 OnTester = 3.475 s.: Count = 3387955, 974951.1 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
iMin = 0 Results[iMin] = 3.330 s.
iMax = 1 Results[iMax] = 3.475 s.
Amount = 2 Mean = 3.402 s. - 89.73%
OnTesterDeinit
------
Interval = 7.584 s., Count = 0, 0.0 unit/sec

It turns out that Trade.mqh is 1.5 times slower than pure MQL5!

I assumed that this was the reason and made a small edit to Trade.mqh.

//+------------------------------------------------------------------+
//| Access functions PositionSelect(...) |
//+------------------------------------------------------------------+
bool CPositionInfo::Select(const string & symbol)
  {
   return(PositionSelect(symbol));
  }

But the brakes of the SB variant have not disappeared.

Where is the dog buried that the SB is so slow?

 

Forum on trading, automated trading systems and testing trading strategies

Libraries: TesterBenchmark

fxsaber, 2017.07.24 14:13

We take the EA from the delivery and run it in the tester, getting such performance data

------
OnTesterInit
i = 0 Pass = 0 OnTester = 2.231 s.: Count = 3387955, 1518581.4 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
i = 1 Pass = 1 OnTester = 2.214 s.: Count = 3387955, 1530241.6 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
iMin = 1 Results[iMin] = 2.214 s.
iMax = 0 Results[iMax] = 2.231 s.
Amount = 2 Mean = 2.223 s. - 79.08%
OnTesterDeinit
------
Interval = 5.621 s., Count = 0, 0.0 unit/sec

This was the Optimisation mode. And now THIS same EA, but in single run mode

Core 1  2017.07.21 23:59:59   Interval = 5.140 s., Count = 3387955, 659135.2 unit/sec
Core 1  EURUSD,M1: 3387955 ticks, 52608 bars generated. Test passed in 0:00:05.164.

A single run on the local Agent is 2.3 times slower than on the same Agent but in Optimisation mode!


Perhaps it is the tester's brakes, so let's see what OnTick profiling will show (execution issues and other trading environment will not affect the result) in Optimisation and Single Run modes.


Optimisation

------
OnTesterInit
i = 0 Pass = 0 OnTester = 2.910 s.: OnTick Profiler: Count = 3387955, Interval = 0.969 s., 3496753.0 unit/sec , Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
i = 1 Pass = 1 OnTester = 2.862 s.: OnTick Profiler: Count = 3387955, Interval = 0.952 s., 3559797.1 unit/sec , Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
iMin = 1 Results[iMin] = 2.862 s.
iMax = 0 Results[iMax] = 2.910 s.
Amount = 2 Mean = 2.886 s. - 78.06%
OnTesterDeinit
------
Interval = 7.394 s., Count = 0, 0.0 unit/sec


Single

Core 1  2017.07.21 23:59:59   Interval = 6.149 s. (Profiler: Count = 3387955, Interval = 4.018 s., 843148.2 unit/sec)
Core 1  EURUSD,M1: 3387955 ticks, 52608 bars generated. Test passed in 0:00:06.162.


The net execution of OnTick itself is as much as 4.2 times slower in Single Run mode than in Optimisation. And that's on the same local Agent!

 
fxsaber:

A single run on the local Agent is 2.3 times slower than on the same Agent but during Optimisation!

The same situation in MT4. Probably, in 4 the brakes are due to log generation during the Single Run.

 
So far, the moral is: instead of single testing, we should run an imaginary optimisation on a single value?
 

I have always wondered which trading API is faster - pure MQL4 or pure MQL5.

Therefore, let's perform OnTick profiling of the same Expert Advisor in MT4/5 to exclude the influence of the performance of the testers themselves.


MT5x64 (Optimisation)

i = 1 Pass = 1 OnTester = 2.862 s.: OnTick Profiler: Count = 3387955, Interval = 0.952 s., 3559797.1 unit/sec , Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641


MT4x86(Single Run)

2017.07.24 15:38:10.770 EURUSD,M1: 1044487 tick events (39659 bars, 1045534 bar states) processed in 0:00:01.903 (total time 0:00:01.997)
2017.07.24 15:38:10.770 2017.07.08 22:10:23  TesterBenchmark_Example EURUSD,M1: Interval = 1.878 s. (Profiler: Count = 1044487, Interval = 1.284 s., 813504.6 unit/sec)


We can conclude that the same trading logic written in MT4 on its pure trading API and written in MT5 on its pure trading API differ in speed as follows.

MT5 is 4.4 times faster than MT4! Note that we are not comparing the speeds of languages, but the speeds of trading APIs for the same TS.

 
Stanislav Korotky:
So far, the moral is this: instead of single testing, we should run imaginary optimisation on a single value?

Yes, if you want it to be fast. At the same time, the trade report should be transmitted from the Agent.

But I think this is a bug and should be fixed.


Sham optimisation on one value is only implemented through one more place - you need at least two passes to run the Optimiser correctly. The second (imaginary) pass should be caught in OnInit with INIT_PARAMETERS_INCORRECT return (or ExpertRemove()).

 
fxsaber:

MT5 is 4.4 times faster than MT4! Note that we compare not the speeds of languages, but the speeds of trading APIs for the same TS.

But still it is interesting how much and which tester is more productive. The TS from the delivery does not use the quotes history, so it is especially good for such a comparison.

We will measure both testers in the Optimisation mode to avoid various nuances.


MT5 (Optimisation)

Forum on trading, automated trading systems and testing trading strategies.

Libraries: TesterBenchmark

fxsaber, 2017.07.24 14:13

------
OnTesterInit
i = 0 Pass = 0 OnTester = 2.231 s.: Count = 3387955, 1518581.4 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
i = 1 Pass = 1 OnTester = 2.214 s.: Count = 3387955, 1530241.6 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1641
iMin = 1 Results[iMin] = 2.214 s.
iMax = 0 Results[iMax] = 2.231 s.
Amount = 2 Mean = 2.223 s. - 79.08%
OnTesterDeinit
------
Interval = 5.621 s., Count = 0, 0.0 unit/sec

MT4 (Single).

2017.07.24 15:58:50.775 EURUSD,M1: 1044487 tick events (39659 bars, 1045534 bar states) processed in 0:00:01.513 (total time 0:00:01.607)
2017.07.24 15:58:50.775 2017.07.08 22:11:32  TesterBenchmark_Example EURUSD,M1: Interval = 1.486 s., Count = 1044487, 702884.9 unit/sec


Since Single slows down in MT4 as well, we do Optimisation and look at the net time in OnTester

We get that the MT4 tester speed is 702884.9 * 1.486 / 0.607 = 1720736.3 ticks/second.


Conclusion: MT4-tester is ~12% faster than MT5-tester.

 
fxsaber:

But still wondering how much and which tester is more productive. The TS from the delivery does not use the history of quotes, so it is especially good for such a comparison.

I.e. just a spherical horse in a vacuum is being compared ) What's the point of a tester without quotes?
 
Alexey Navoykov:
I.e. just a spherical horse in a vacuum is compared ). What is the point of a tester without quotes?

The tester generates quotes, but the TS itself does not use it, so as not to clog the result with the difference in the implementation of High[] and CopyHigh.

The tester creates the trading environment, including history. And it is the tester that we were measuring, not user requests (not to be confused with the formation) of history, which are implemented in platforms in fundamentally different ways.

The same problem with measuring the performance of trading APIs.

 
fxsaber:

We take the Expert Advisor from the delivery and run it in the tester, getting such performance data

Now let's run the same Expert Advisor, but using Trade.mqh

It turns out that Trade.mqh is 1.5 times slower than pure MQL5!

I assumed that this was the reason and made a small edit to Trade.mqh.

But the brakes of the SB variant have not disappeared.

Where is the dog buried that the SB is so slow?

The developers have tweaked something in 1648 and fixed some bugs, so I managed to estimate the performance of one more trade library.

The current situation is as follows.


Pure MQL5

------
OnTesterInit
i = 0 Pass = 0 OnTester = 13.451 s.: Count = 19469844, 1447464.4 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 1 Pass = 1 OnTester = 10.904 s.: Count = 19469844, 1785569.0 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 2 Pass = 2 OnTester = 10.895 s.: Count = 19469844, 1787044.0 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 3 Pass = 3 OnTester = 10.898 s.: Count = 19469844, 1786552.0 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 4 Pass = 4 OnTester = 10.889 s.: Count = 19469844, 1788028.7 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
iMin = 4 Results[iMin] = 10.889 s.
iMax = 0 Results[iMax] = 13.451 s.
Amount = 5 Mean = 11.407 s. - 89.58%
OnTesterDeinit
------
Interval = 63.675 s., Count = 0, 0.0 unit/sec


#include <Trade\Trade.mqh>

------
OnTesterInit
i = 0 Pass = 0 OnTester = 14.390 s.: Count = 19469844, 1353012.1 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 1 Pass = 1 OnTester = 13.044 s.: Count = 19469844, 1492628.3 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 2 Pass = 2 OnTester = 13.016 s.: Count = 19469844, 1495839.3 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 3 Pass = 3 OnTester = 13.014 s.: Count = 19469844, 1496069.2 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 4 Pass = 4 OnTester = 13.039 s.: Count = 19469844, 1493200.7 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
iMin = 3 Results[iMin] = 13.014 s.
iMax = 0 Results[iMax] = 14.390 s.
Amount = 5 Mean = 13.301 s. - 94.05%
OnTesterDeinit
------
Interval = 70.713 s., Count = 0, 0.0 unit/sec


#include <MT4Orders.mqh>

------
OnTesterInit
i = 0 Pass = 0 OnTester = 14.385 s.: Count = 19469844, 1353482.4 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 1 Pass = 1 OnTester = 11.434 s.: Count = 19469844, 1702802.5 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 2 Pass = 2 OnTester = 11.459 s.: Count = 19469844, 1699087.5 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 3 Pass = 3 OnTester = 11.440 s.: Count = 19469844, 1701909.4 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
i = 4 Pass = 4 OnTester = 11.426 s.: Count = 19469844, 1703994.7 unit/sec, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent-127.0.0.1-3000 build = 1648
iMin = 4 Results[iMin] = 11.426 s.
iMax = 0 Results[iMax] = 14.385 s.
Amount = 5 Mean = 12.029 s. - 91.20%
OnTesterDeinit
------
Interval = 65.946 s., Count = 0, 0.0 unit/sec


The places were distributed as follows

  1. Pure MQL5 - 100% performance.
  2. MT4Orders.mqh - ~95% performance.
  3. SB Trade\Trade.mqh - ~84% performance.
SB started to lag less.


ZЫ I wonder how much other trade libraries show ...

ZЫ2 What are those brakes in 1648 on the first pass of each pack? In 1643 it was like this

Forum on trading, automated trading systems and testing trading strategies.

Features of mql5 language, subtleties and techniques of work

fxsaber, 2017.08.15 17:16

In the first pass of a batch of Agent jobs (for example, in a single tester run), the time between the start of the Expert Advisor and the first NewTick event can take several seconds. On the next passes of the batch this time is zero.

It is as if the tester immediately makes a NewTick event in 1648. Which, of course, is wrong.