TSNStd/Src/TestVar/UView.mq5
Nique_372 1dc77364ec
2026-10-09 12:56:38 -05:00

87 lines
2.3 KiB
MQL5

//+------------------------------------------------------------------+
//| UView.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 "..\\String\\UView.mqh"
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CUcharBuffer
{
public:
CUcharBuffer(void) {}
~CUcharBuffer(void) {}
//---
uchar m_raw[];
};
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
CUcharBuffer buff;
ArrayResize(buff.m_raw, 1024);
ArrayInitialize(buff.m_raw, 'A');
buff.m_raw[900] = 'B';
//---
TSN::CStringView<CUcharBuffer> view(0, 1024, &buff);
//---
int kswar = 0, k_normal = 0;
ulong tswar = 0, tnormal = 0;
//---
for(int i = 0; i < 8; i++)
{
for(int x = 0; x < 2; x++)
{
//---
const bool is = x == 0;
ulong a = GetMicrosecondCount();
//---
if(is)
{
for(int y = 0; y < 100000; y++)
k_normal += view.Find('B');
}
else
{
for(int y = 0; y < 100000; y++)
kswar += view.FindWithSwar('B');
}
ulong b = GetMicrosecondCount() - a;
//---
if(is)
{
tnormal += b;
}
else
{
tswar += b;
}
}
}
//---
Print("Find: ", tnormal, " k: ", k_normal);
Print("FindWithSwar ", tswar, " k: ", kswar);
}
//+------------------------------------------------------------------+