Benchmark - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources
The include file " benchmark.mqh " has a set of macros to benchmark the execution speed of various functions to decide which function is the fastest.
//+------------------------------------------------------------------+ //|Macro for measuring function execution time. | //|Print the time in microseconds each call took (microseconds/call). | //| TimeIt(sum += ArrayBsearch(arr, value)); | //+------------------------------------------------------------------+ #Define TimeIt (function call) //+--------------------------------------------------------------------------------+ //|Macro used to execute a certain function a fixed number of times. | //|Print the elapsed time in milliseconds (msec). | //|Benchmark(repeat, sum + = ArrayBsearch(arr, value)); | //+------------------------------------------------------------------+ #define benchmark (repeat, func_inspiration) //+----------------------------------------------------------------------------------+ //|Macro for executing a function for a fixed duration in milliseconds. | //|Print the number of operations per second (ops/sec). | //| Benchmark_opsec(msec, sum += ArrayBsearch(arr, value)); | //+------------------------------------------------------------------+ #define Benchmark_opsec(ms, func_invocacy)
The library is based on the following public source code time module in Python https://docs.python.org/3/library/timeit.html and stopwatch class from C# https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch
Here is a usage example script:
Attachment download
📎 benchmark.mqh (9.43 KB)
📎 stopwatch.mqh (11.37 KB)
📎 benchmark_test.mq5 (1.45 KB)
Source: MQL5 #43910
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •