ICTLibraryEasy/Examples/Benchmark/Final/Main.mqh

145 lines
5.4 KiB
MQL5
Raw Permalink Normal View History

2026-01-14 07:41:55 -05:00
//+------------------------------------------------------------------+
//| Main.mqh |
//| Copyright 2025, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372"
#property strict
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "..\\..\\..\\..\\GrapichsByLeo\\Histogram\\Main.mqh"
#include "..\\Utils\\Base.mqh"
// https://forge.mql5.io/nique_372/GrapichsByLeo
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
struct MetricData
{
string label;
uint ms_duracion;
int memory_use;
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
typedef bool (*MetricSortByMs)(const MetricData& a, const MetricData& b);
typedef bool (*MetricSortByMem)(const MetricData& a, const MetricData& b);
__forceinline bool MetricSortFunc_ByMs(const MetricData& a, const MetricData& b) { return a.ms_duracion > b.ms_duracion; }
__forceinline bool MetricSortFunc_ByMem(const MetricData& a, const MetricData& b) { return a.memory_use > b.memory_use; }
//--- Para el texto en ejes
__forceinline string MetricTextFunc_ByMs(double value, int8_t decimals) { return DoubleToString(value, 0) + " ms"; }
__forceinline string MetricTextFunc_ByMem(double value, int8_t decimals) { return DoubleToString(value, 1) + " mb"; }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CMetrics
{
private:
MetricData m_data[TOTAL_FVG_TEST];
public:
CMetrics(void) {}
~CMetrics(void) {}
//---
void Init();
//---
void Plot(uint back_color, const string& file_name, bool comon);
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CMetrics::Init(void)
{
//---
for(int i = 0; i < TOTAL_FVG_TEST; i++)
{
ResetLastError();
const int fh = FileOpen(g_benchk_filenames[i], FILE_READ | FILE_TXT | FILE_COMMON);
if(fh == INVALID_HANDLE)
{
FastLog(FUNCION_ACTUAL, ERROR_TEXT, StringFormat("Error al abrir el archivo = %s, ultimo error = %d", g_benchk_filenames[i], GetLastError()));
Remover();
return;
}
//---
m_data[i].ms_duracion = uint(FileReadString(fh));
m_data[i].memory_use = int(FileReadString(fh));
m_data[i].label = g_benchk_names[i];
FileClose(fh);
}
ArrayPrint(m_data, 2, " | ");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CMetrics::Plot(uint back_color, const string& file_name, bool comon)
{
//---
CCanvasCustom canvas;
canvas.CreateBitmapLabel(0, 0, "Comparacion", 30, 0, 1050, 550, COLOR_FORMAT_ARGB_RAW);
canvas.Erase(back_color);
//--- Plot 1
CHistogramVertical hist1;
hist1.Initialize(&canvas, 5, 5, 550, 540, 0xFFFFFFFF);
hist1.TituloDefault("Velocidad MS");
// Datos
CSimpleSort::SortDescendente(m_data, (MetricSortByMs)MetricSortFunc_ByMs);
for(int i = 0; i < TOTAL_FVG_TEST; i++)
{
hist1.AddConjuntoBar(m_data[i].label, 12, "Arial", HISTOGRAM_TEXT_MODE_LEFT_UPPER, 1, 50, HIST_DRAW_RECT_FILL, 0); // Ya ocnifugra el ptr de lectura
hist1.AddBarToConjuntoBarFast(double(m_data[i].ms_duracion), hist1.GetColorGeneratorPointer().Next());
}
// Lienzo
hist1.InitLienzoBarras(75, 80, 540, 530, 5, 5, 10);
hist1.CreateBordesEjesGridsSimple(HIST_LINE_MODE_IZQUIERDA, 10, true, 4278190080, 4287730065, MetricTextFunc_ByMs);
//--- Plot 2
CHistogramVertical hist2;
hist2.Initialize(&canvas, 565, 5, 1040, 540, 0xFFFFFFFF);
hist2.TituloDefault("Consumo en mb");
// Datos
CSimpleSort::SortDescendente(m_data, (MetricSortByMs)MetricSortFunc_ByMem);
for(int i = 0; i < TOTAL_FVG_TEST; i++)
{
hist2.AddConjuntoBar(m_data[i].label, 12, "Arial", HISTOGRAM_TEXT_MODE_LEFT_UPPER, 1, 50, HIST_DRAW_RECT_FILL, 0); // Ya ocnifugra el ptr de lectura
hist2.AddBarToConjuntoBarFast(double(m_data[i].memory_use), hist1.GetColorGeneratorPointer().Next());
}
// Lienzo
hist2.InitLienzoBarras(75, 80, 465, 530, 5, 5, 10);
hist2.CreateBordesEjesGridsSimple(HIST_LINE_MODE_IZQUIERDA, 10, true, 4278190080, 4287730065, MetricTextFunc_ByMem);
//---
hist1.Redraw();
hist2.Redraw();
//---
Sleep(15000);
//--- Gurdamos
canvas.Save(file_name, comon);
canvas.Destroy();
}
//+------------------------------------------------------------------+