TimeUtils/performance_mode.mq5
2025-09-19 20:26:04 +00:00

42 lines
3.2 KiB
MQL5

//+------------------------------------------------------------------+
//| performance_mode.mq5 |
//| Copyright © 2024, Amr Ali |
//| https://www.mql5.com/en/users/amrali |
//+------------------------------------------------------------------+
// optionally adjust performance via #defines before #include
// enable performance mode for library
//#define TIMEUTILS_PERFORMANCE_MODE
#include "TimeUtils.mqh"
#define BENCHSIZE 30000000
void OnStart()
{
datetime t[]; // array of random dates for testing
ArrayResize(t, BENCHSIZE);
for(int i = 0; i < BENCHSIZE; i++)
t[i] = datetime((((ulong)rand()<<60)|((ulong)rand()<<45)
|((ulong)rand()<<30)|((ulong)rand()<<15)
|(ulong)rand())%(ulong(365)*130*3600*24));
Print("Processing random times " + (string)t[ArrayMinimum(t)] + " - " + (string)t[ArrayMaximum(t)]);
bool res = false; // Testing performance
ulong tt = GetMicrosecondCount();
for(int i = 0; i < BENCHSIZE; i++)
res |= (bool)(StartOfMonth(t[i]) + EndOfMonth(t[i])); // both are calling TimeToStruct and StructToTime, internally.
tt = GetMicrosecondCount()-tt;
Print(StringFormat("%5.2f", tt*1000.0/BENCHSIZE) + " ns per call, result = " + string(res));
}
//+------------------------------------------------------------------+
/*
example output with TIMEUTILS_PERFORMANCE_MODE
Processing random times 1970.01.01 00:00:15 - 2099.11.29 23:56:41
9.69 ns per call, result = true
*/