Download MetaTrader 5

measure time to execute code (speedtest)

To add comments, please log in or register
AwarenessForex
32
AwarenessForex  

either in tester or live chart EA/indicator/script, I would like to know how long it takes for a section of code or the entire EA to run through complete sequence. 

I checked a thread here which had a speedtest.mq4 attached, but I could not ascertain how to apply it to my situation. Could use MQ's sample code to demonstrate.

Carl Schreiber
7295
Carl Schreiber  
AwarenessForex:

either in tester or live chart EA/indicator/script, I would like to know how long it takes for a section of code or the entire EA to run through complete sequence. 

I checked a thread here which had a speedtest.mq4 attached, but I could not ascertain how to apply it to my situation. Could use MQ's sample code to demonstrate.

Use the example of GetTickCount() (in the editor put the cursor above the function an press F1) but be aware the if coded correctl< you'll get 0 mSec execution time as the minimal resolution for the cpu is ~16 mSec.
Meng Yin Teoh
1587
Meng Yin Teoh  
AwarenessForex:

either in tester or live chart EA/indicator/script, I would like to know how long it takes for a section of code or the entire EA to run through complete sequence. 

I checked a thread here which had a speedtest.mq4 attached, but I could not ascertain how to apply it to my situation. Could use MQ's sample code to demonstrate.


use GetTickCount().

Documentation on MQL5: Common Functions / GetTickCount
Documentation on MQL5: Common Functions / GetTickCount
  • www.mql5.com
Common Functions / GetTickCount - Reference on algorithmic/automated trading language for MetaTrader 5
whroeder1
15925
whroeder1  
That link is ancient. A lot has changed since February 3, 2014 (Build 600) including the build in profiler (editor: debug.)
Stanislav Korotky
21581
Stanislav Korotky  
I'm not sure the built-in profiler can run in the tester. Yet profiling in the tester can collect more data than while debugging on a chart. For this case you can implement a kind of profiler in MQL - here is an example in my blog.
AwarenessForex
32
AwarenessForex  
Stanislav Korotky:
I'm not sure the built-in profiler can run in the tester. Yet profiling in the tester can collect more data than while debugging on a chart. For this case you can implement a kind of profiler in MQL - here is an example in my blog.


Looks like it cannot run in tester mode (built-in profiler).  And you need the market to be open (with ticks coming in).   But it doesn't provide other statistics like how many loops took place, how long it takes to loop through to different major sections (onTick, OnInit, etc).

But I want something that I can inject into the beginning and end of my code to verify how long it is taking to complete the sequence.  So do you store getTickCount() at the beginning and end of the code and then subtract the difference?

whroeder1
15925
whroeder1  
AwarenessForex: Looks like it cannot run in tester mode (built-in profiler).
It doesn't need to.
  1. First, get the code working.
  2. Second, then profile working code.
  3. Then, only if it shows you need to, optimize.
Blahtech Limited
5492
James Cater  
whroeder1:
It doesn't need to.
  1. First, get the code working.
  2. Second, then profile working code.
  3. Then, only if it shows you need to, optimize.

If you run an EA with the profiler it may be skewed towards the startup costs leaving the tick based costs a little buried in the stats.

To improve the results I would recommend leaving it running for a few minutes in active markets to give you a decent number of ticks to work with

Stanislav Korotky
21581
Stanislav Korotky  
AwarenessForex:


But it doesn't provide other statistics like how many loops took place, how long it takes to loop through to different major sections (onTick, OnInit, etc).

But I want something that I can inject into the beginning and end of my code to verify how long it is taking to complete the sequence.  So do you store getTickCount() at the beginning and end of the code and then subtract the difference?

If you use MQL-based custom profiler you can measure all you want. And do it in the tester, which brings better coverage of code execution.

Take a look into the code to understand how to insert profiling objects in order to update tick counts automatically (GetTickCount is used behind the scene). I'm afraid this will require 1-2 additional lines for every scope (function, cycle, etc) which you need to measure.

Alain Verleyen
Moderator
33339
Alain Verleyen  

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Как вы ищете ошибки в программе?

Renat Fatkhullin, 2017.05.30 21:39

Для информации: мы в следующем билде выпустим профайлер на исторических данных, что позволит оптимизировать программы оораздо легче.

Плюс пофиксим тормоза на доступе к истории, особенно на мервых инструментах. Можно будет легко писать глобальные сканеры символов без тормозов.
In next MT5 build, will be profiler on historical data, a great news !
Carl Schreiber
7295
Carl Schreiber  
Alain Verleyen:
In next MT5 build, will be profiler on historical data, a great news !

Do you know whether Metaquotes will reveal the formate of the hist. data so that we would be able to create tickdata from our own database?

12
To add comments, please log in or register