//+------------------------------------------------------------------+ //| 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 "Base64.mqh" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- const int InpIterations = 30; //--- int size = 800 * 600 * 4; // ARGB uchar src[]; ArrayResize(src, size); MathSrand(42); for(int i = 0; i < size; i++) src[i] = (uchar)MathRand(); uchar key[]; // vacío para CRYPT_BASE64 uchar dNativo[], dPuro[]; // 1) Verificación de correctitud CryptEncode(CRYPT_BASE64, src, key, dNativo); const int j = TSN::CBase64::Encode(src, size, 0, dPuro, 0); ArrayResize(dPuro, j); bool iguales = (ArraySize(dNativo) == ArraySize(dPuro)) && (ArrayCompare(dNativo, dPuro) == 0); Print("Salidas idénticas: ", iguales ? "SÍ" : "NO", " | tamaño nativo=", ArraySize(dNativo), " puro=", ArraySize(dPuro)); if(!iguales) { Print("Abortando benchmark: las salidas no coinciden."); return; } // 3) Benchmark ulong tNativo = 0; ulong tPuro = 0; for(int k = 0; k < InpIterations; k++) { ulong t0 = GetMicrosecondCount(); CryptEncode(CRYPT_BASE64, src, key, dNativo); tNativo += GetMicrosecondCount() - t0; t0 = GetMicrosecondCount(); TSN::CBase64::Encode(src, size, 0, dPuro, 0); tPuro += GetMicrosecondCount() - t0; } double msNativo = tNativo / 1000.0 / InpIterations; double msPuro = tPuro / 1000.0 / InpIterations; Print("Entrada: ", size, " bytes, ", InpIterations, " iteraciones"); Print("CryptEncode (nativo): ", DoubleToString(msNativo, 3), " ms promedio"); Print("Base64 MQL5 puro : ", DoubleToString(msPuro, 3), " ms promedio"); if(msNativo > 0) Print("Relación puro/nativo: ", DoubleToString(msPuro / msNativo, 4), "x"); Print(dPuro[0] == dNativo[0]); } //+------------------------------------------------------------------+