fast_json/Tests/TestJsonScreenshot.mq5
2026-01-25 23:39:19 -03:00

46 lignes
1,6 Kio
MQL5

//+------------------------------------------------------------------+
//| TestJsonScreenshot.mq5 |
//| AI-Toolkit |
//+------------------------------------------------------------------+
#property script_show_inputs
#include "../fast_json.mqh"
#include <JAson.mqh>
input int Loops = 50000;
void OnStart() {
Print("Running Benchmark (50k iters)... Wait...");
string json = "{\"id\":12345,\"mode\":\"swar\",\"rates\":[1.1,1.2,1.3,1.4,1."
"5],\"users\":[{\"id\":1,\"n\":\"A\"},{\"id\":2,\"n\":\"B\"}]}";
// --- 1. LEGACY (JAson) ---
CJAVal jason;
ulong t0 = GetMicrosecondCount();
for (int i = 0; i < Loops; i++)
jason.Deserialize(json);
ulong t_jason = GetMicrosecondCount() - t0;
// --- 2. AI-TOOLKIT (NewLib) ---
CJson toolkit;
t0 = GetMicrosecondCount();
for (int i = 0; i < Loops; i++)
toolkit.Parse(json);
ulong t_toolkit = GetMicrosecondCount() - t0;
// --- 3. OUTPUT TABLE ---
double speedup = (double)t_jason / (double)t_toolkit;
Print(""); // Spacer
Print("========================================");
Print(" JSON PARSER BENCHMARK (50k) ");
Print("========================================");
PrintFormat(" %-12s | %-10s | %s", "LIBRARY", "TIME (ms)", "RESULT");
Print("----------------------------------------");
PrintFormat(" %-12s | %-10d | %s", "JAson (Old)", t_jason / 1000,
"1.0x (Baseline)");
PrintFormat(" %-12s | %-10d | %.1fx FASTER", "AI-Toolkit", t_toolkit / 1000,
speedup);
Print("========================================");
Print("");
}