FastCollectionsByLeo/Test/Final.mq5
Nique_372 10ea24d943
2026-07-19 09:25:59 -05:00

142 lines
No EOL
4.3 KiB
MQL5

//+------------------------------------------------------------------+
//| Final.mq5 |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com/"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include <TSN\\MQLArticles\\Utils\\EnumReg.mqh>
#include "..\\Src\\ColHash\\HashMap\\All.mqh"
#include "..\\Src\\ColHash\\Dict\\DictT.mqh"
#include <Generic\\HashMap.mqh>
#include "..\\Src\\ColHash\\Hash\\Generic.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
const string g_tf_keys[21] =
{
"PERIOD_M1", "PERIOD_M2", "PERIOD_M3", "PERIOD_M4", "PERIOD_M5", "PERIOD_M6",
"PERIOD_M10", "PERIOD_M12", "PERIOD_M15", "PERIOD_M20", "PERIOD_M30",
"PERIOD_H1", "PERIOD_H2", "PERIOD_H3", "PERIOD_H4", "PERIOD_H6", "PERIOD_H8", "PERIOD_H12",
"PERIOD_D1", "PERIOD_W1", "PERIOD_MN1"
};
const ENUM_TIMEFRAMES g_tf_values[21] =
{
PERIOD_M1, PERIOD_M2, PERIOD_M3, PERIOD_M4, PERIOD_M5, PERIOD_M6,
PERIOD_M10, PERIOD_M12, PERIOD_M15, PERIOD_M20, PERIOD_M30,
PERIOD_H1, PERIOD_H2, PERIOD_H3, PERIOD_H4, PERIOD_H6, PERIOD_H8, PERIOD_H12,
PERIOD_D1, PERIOD_W1, PERIOD_MN1
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
ENUM_TIMEFRAMES StringToTimeframe(const string& s)
{
for(int i = 0; i < 21; i++)
if(g_tf_keys[i] == s)
return g_tf_values[i];
return PERIOD_CURRENT;
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
const int ti = 100000;
CDictSValue<int> dict1;
CHashMap<string, int> dict2;
CHashMapFast(string, int) dict3;
for(int i = 0; i < 21; i++)
{
dict1.Add(g_tf_keys[i], g_tf_values[i]);
dict2.Add(g_tf_keys[i], g_tf_values[i]);
dict3.Add(g_tf_keys[i], g_tf_values[i]);
}
//---
MathSrand(100);
int v;
ulong a = GetMicrosecondCount();
for(int i = 0; i < ti; i++)
{
dict1.TryGet(g_tf_keys[MathRand() % 21], v);
}
ulong b = GetMicrosecondCount();
Print("DictSValue: ", (b - a));
//---
MathSrand(100);
a = GetMicrosecondCount();
for(int i = 0; i < ti; i++)
{
dict2.TryGetValue(g_tf_keys[MathRand() % 21], v);
}
b = GetMicrosecondCount();
Print("CHashMap: ", (b - a));
//---
MathSrand(100);
//---
a = GetMicrosecondCount();
for(int i = 0; i < ti; i++)
{
dict3.TryGet(g_tf_keys[MathRand() % 21], v);
}
b = GetMicrosecondCount();
Print("CHashMapFast: ", (b - a));
//---
MathSrand(100);
//---
a = GetMicrosecondCount();
for(int i = 0; i < ti; i++)
{
v = TSN::CEnumRegBasis::GetVal(g_tf_keys[MathRand() % 21], 0);
}
b = GetMicrosecondCount();
Print("Perfect hash: ", (b - a));
//---
MathSrand(100);
//---
a = GetMicrosecondCount();
for(int i = 0; i < ti; i++)
{
v = StringToTimeframe(g_tf_keys[MathRand() % 21]);
}
b = GetMicrosecondCount();
Print("linear: ", (b - a));
}
//+------------------------------------------------------------------+
/*
2026.07.15 07:55:34.576 Final (EURUSD,M1) DictSValue: 2466
2026.07.15 07:55:34.585 Final (EURUSD,M1) CHashMap: 8750
2026.07.15 07:55:34.586 Final (EURUSD,M1) CHashMapFast: 1925
2026.07.15 07:55:34.588 Final (EURUSD,M1) Perfect hash: 1705
2026.07.15 07:55:34.598 Final (EURUSD,M1) linear: 9818
2026.07.15 07:55:37.148 Final (EURUSD,M1) DictSValue: 2438
2026.07.15 07:55:37.157 Final (EURUSD,M1) CHashMap: 8827
2026.07.15 07:55:37.159 Final (EURUSD,M1) CHashMapFast: 1949
2026.07.15 07:55:37.160 Final (EURUSD,M1) Perfect hash: 1706
2026.07.15 07:55:37.170 Final (EURUSD,M1) linear: 9869
*/