CryptoByLeo/Src/Hash/Test/Tesrt.mq5

53 lines
1.9 KiB
MQL5
Raw Permalink Normal View History

2026-08-11 10:06:33 -05:00
//+------------------------------------------------------------------+
//| Tesrt.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 "..\\SHA256.mqh"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
2026-08-12 19:41:32 -05:00
int MB = 1;
2026-08-11 10:06:33 -05:00
2026-08-12 19:41:32 -05:00
int n = MB * 1024 * 1024;
2026-08-11 10:06:33 -05:00
uchar data[];
ArrayResize(data, n);
MathSrand(42);
for(int i = 0; i < n; i++)
data[i] = (uchar)(MathRand() % 256);
uchar fin[CRYPTOBYLEO_SHA256_SIZET_FHASH];
uchar key[];
ulong a = GetMicrosecondCount();
2026-08-12 19:41:32 -05:00
for(int i = 0; i < 50; i++)
2026-08-12 18:18:45 -05:00
{
TSN::CCryptoHash::SHA256(data, n, fin);
}
2026-08-11 10:06:33 -05:00
ulong b = GetMicrosecondCount();
double t1 = (b - a) / 1000000.0;
2026-08-12 18:18:45 -05:00
Print("MQL5 SHA256: ", t1, " s ", (MB / t1), " MB/s", " dumm: " , fin[0]);
2026-08-11 10:06:33 -05:00
a = GetMicrosecondCount();
2026-08-12 19:41:32 -05:00
for(int i = 0; i < 50; i++)
2026-08-12 18:18:45 -05:00
{
CryptEncode(CRYPT_HASH_SHA256, data, key, fin);
}
2026-08-11 10:06:33 -05:00
b = GetMicrosecondCount();
double t2 = (b - a) / 1000000.0;
2026-08-12 18:18:45 -05:00
Print("CryptEncode: ", t2, " s ", (MB / t2), " MB/s", " dumm: " , fin[0]);
2026-08-11 10:06:33 -05:00
Print("ratio: ", (t1 > t2 ? t1 / t2 : t2 / t1), (t1 > t2 ? " CryptEncode gana" : " MQL5 gana"));
}
//+------------------------------------------------------------------+