거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Benchmark - MetaTrader 5용 라이브러리

조회수:
2948
평가:
(14)
게시됨:
2023.04.17 19:24
업데이트됨:
2023.04.27 08:59
\MQL5\Include\Benchmark\
Benchmark.mqh (9.43 KB) 조회
Stopwatch.mqh (11.37 KB) 조회
\MQL5\Scripts\
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

The include file "Benchmark.mqh" has a set of macros to benchmark various functions for their execution speeds to decide which is the fastest one.

//+------------------------------------------------------------------+
//| Macro to measure the execution time a function.                  |
//| Prints the elapsed time in microseconds per call (µsec/call).    |
//| TimeIt(sum += ArrayBsearch(arr, value));                         |
//+------------------------------------------------------------------+
#define TimeIt(func_invocation)


//+------------------------------------------------------------------+
//| Macro to execute a function for a fixed number of times.         |
//| Prints the elapsed time in milliseconds (msec).                  |
//| Benchmark(repeats, sum += ArrayBsearch(arr, value));             |
//+------------------------------------------------------------------+
#define Benchmark(repeats, func_invocation)


//+------------------------------------------------------------------+
//| Macro to execute a function for a fixed duration in msec.        |
//| Prints the number of operations per second (ops/sec).            |
//| Benchmark_opsec(msec, sum += ArrayBsearch(arr, value));          |
//+------------------------------------------------------------------+
#define Benchmark_opsec(msec, func_invocation)


The library is based on public source codes of timeit 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 an example script for usage:

//+------------------------------------------------------------------+
//|                                               benchmark_test.mq5 |
//|                                        Copyright © 2018, Amr Ali |
//|                             https://www.mql5.com/en/users/amrali |
//+------------------------------------------------------------------+
#include <Benchmark\Benchmark.mqh>

//+------------------------------------------------------------------+
//| The function returns integer numeric value closest from below.   |
//+------------------------------------------------------------------+
double FastFloor(const double v)
  {
   double k = (double)(long)v;
   return k - (v < k);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart(void)
  {
   int repeats = 1e8;
   Print("repeats=",repeats);

//--- if result of the expression is not used, compiler optimizes out
//--- (i.e., ignores) the function call.
   double sum = 0;

   Benchmark(repeats, sum += MathFloor(__i));
   Benchmark(repeats, sum += FastFloor(__i));

   Print("sum=",sum);
  }
//+------------------------------------------------------------------+

// sample output:
/*
 repeats=100000000
 sum+=MathFloor(__i) -> 599 msec
 sum+=FastFloor(__i) -> 138 msec
 sum=9999999922280040.0
*/
    Money Management Money Management

    Close trades when the percentage profit or risk of the account is reached

    Tick Speed Indicator Tick Speed Indicator

    This example was created to see how long it takes to reach 100 ticks. So this indicator is a seconds / "centick" (centick = 100 ticks). It helps you trade orders flow.

    Volume Average Groups For Comparison Volume Average Groups For Comparison

    Learn how to split the volume data into different groups so that you can compare them and create a strategy based on volume average.

    ChartButton Class MT5 ChartButton Class MT5

    This class allows you to create buttons on the chart as if they were chart objects(have time and price coordinates) these objects can be dragged on the chart and when scrolling they stay at the same place. If you wan't to learn some Object Oriented Programming or if you wan't to understand how chartevents work or you wan't to create graphical interfaces, you can learn a lot from this.