MQLArticles/RM/RM_Test.mq5

112 lines
2.6 KiB
MQL5

//+------------------------------------------------------------------+
//| Test.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 |
//+------------------------------------------------------------------+
#include "Old\\TicketsTable.mqh"
#include "TicketsTable.mqh"
#include <Generic/HashMap.mqh>
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
MathSrand(20);
Position val[];
#define TOTAL_POS 20
ArrayResize(val, TOTAL_POS);
val[0].ticket = 16815 + (MathRand() % 100);
for(int i = 1; i < TOTAL_POS; i++)
{
val[i].ticket = val[i - 1].ticket + (MathRand() % 100);
}
//---
TSN::CTicketsTable m_table_2;
CTicketsInfo m_table_1;
CHashMap<ulong, int> hashmap;
Sleep(100);
//---
for(int i = 0; i < TOTAL_POS; i++)
{
m_table_1.Add(val[i]);
m_table_2.Add(val[i]);
hashmap.Add(val[i].ticket, i);
}
//---
Position temp;
Sleep(250);
//--- Lieanl
MathSrand(20);
ulong a = GetMicrosecondCount();
for(int i = 0; i < 100000; i++)
{
const ulong ticket = (ulong)MathRand();
for(int a = 0; a < TOTAL_POS; a++)
{
if(val[a].ticket == ticket)
{
temp = val[a];
break;
}
}
}
ulong b = GetMicrosecondCount();
Print("time lineal: ", (b - a));
//---
Sleep(100);
//---
MathSrand(20);
a = GetMicrosecondCount();
for(int i = 0; i < 100000; i++)
{
m_table_1.GetByTicket(MathRand(), temp);
}
b = GetMicrosecondCount();
Print("time prev: ", (b - a));
//---
Sleep(100);
//---
MathSrand(20);
a = GetMicrosecondCount();
for(int i = 0; i < 100000; i++)
{
int k;
hashmap.TryGetValue(MathRand(), k);
}
b = GetMicrosecondCount();
Print("time hashmap: ", (b - a));
//---
Sleep(100);
//---
MathSrand(20);
a = GetMicrosecondCount();
for(int i = 0; i < 100000; i++)
{
m_table_2.GetByTicket(MathRand(), temp);
}
b = GetMicrosecondCount();
Print("time fast: ", (b - a));
}
//+------------------------------------------------------------------+