MQLArticles/RM/RM_Test.mq5

112 lines
2.6 KiB
MQL5
Raw Permalink Normal View History

2026-07-28 08:55:53 -05:00
//+------------------------------------------------------------------+
//| 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>
2026-07-28 08:55:53 -05:00
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
MathSrand(20);
Position val[];
#define TOTAL_POS 20
2026-07-28 21:50:57 -05:00
ArrayResize(val, TOTAL_POS);
2026-07-28 09:08:36 -05:00
val[0].ticket = 16815 + (MathRand() % 100);
2026-07-28 08:55:53 -05:00
2026-07-28 21:50:57 -05:00
for(int i = 1; i < TOTAL_POS; i++)
2026-07-28 08:55:53 -05:00
{
2026-07-28 09:08:36 -05:00
val[i].ticket = val[i - 1].ticket + (MathRand() % 100);
2026-07-28 08:55:53 -05:00
}
//---
TSN::CTicketsTable m_table_2;
CTicketsInfo m_table_1;
2026-07-28 09:08:36 -05:00
CHashMap<ulong, int> hashmap;
2026-07-28 08:55:53 -05:00
2026-07-28 21:50:57 -05:00
Sleep(100);
2026-07-28 08:55:53 -05:00
//---
2026-07-28 21:50:57 -05:00
for(int i = 0; i < TOTAL_POS; i++)
2026-07-28 08:55:53 -05:00
{
m_table_1.Add(val[i]);
m_table_2.Add(val[i]);
2026-07-28 09:08:36 -05:00
hashmap.Add(val[i].ticket, i);
2026-07-28 08:55:53 -05:00
}
2026-07-28 21:50:57 -05:00
//---
2026-07-28 08:55:53 -05:00
Position temp;
2026-07-28 21:50:57 -05:00
Sleep(250);
2026-07-28 08:55:53 -05:00
//--- Lieanl
MathSrand(20);
ulong a = GetMicrosecondCount();
for(int i = 0; i < 100000; i++)
{
const ulong ticket = (ulong)MathRand();
2026-07-28 21:50:57 -05:00
for(int a = 0; a < TOTAL_POS; a++)
2026-07-28 08:55:53 -05:00
{
if(val[a].ticket == ticket)
{
temp = val[a];
break;
}
}
}
ulong b = GetMicrosecondCount();
2026-07-28 09:08:36 -05:00
Print("time lineal: ", (b - a));
2026-07-28 08:55:53 -05:00
2026-07-28 21:50:57 -05:00
//---
Sleep(100);
2026-07-28 08:55:53 -05:00
//---
MathSrand(20);
a = GetMicrosecondCount();
for(int i = 0; i < 100000; i++)
{
m_table_1.GetByTicket(MathRand(), temp);
}
b = GetMicrosecondCount();
2026-07-28 09:08:36 -05:00
Print("time prev: ", (b - a));
2026-07-28 21:50:57 -05:00
//---
Sleep(100);
2026-07-28 09:08:36 -05:00
//---
MathSrand(20);
a = GetMicrosecondCount();
for(int i = 0; i < 100000; i++)
{
int k;
hashmap.TryGetValue(MathRand(), k);
}
b = GetMicrosecondCount();
Print("time hashmap: ", (b - a));
2026-07-28 08:55:53 -05:00
2026-07-28 21:50:57 -05:00
//---
Sleep(100);
2026-07-28 08:55:53 -05:00
//---
MathSrand(20);
a = GetMicrosecondCount();
for(int i = 0; i < 100000; i++)
{
m_table_2.GetByTicket(MathRand(), temp);
}
b = GetMicrosecondCount();
2026-07-28 09:08:36 -05:00
Print("time fast: ", (b - a));
2026-07-28 08:55:53 -05:00
}
//+------------------------------------------------------------------+