//+------------------------------------------------------------------+ //| FastJsonBench.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 //#define JSONBENCH_RUN_PARSE //#define JSONBENCH_RUN_MIX //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "Def.mqh" // NOTA: // Se esta usando uan version modificada (de mi parte) pero solo modificaque tema de public\private // Para que peuda tener acceso al buffer y hacer el one copy una sola vez... por que la liberia no lo trae // por defecto #include "..\\..\\..\\fast_json\\fast_json.mqh" // FastJson #define LIBNAME "FastJson" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- CJson json; #ifdef JSONBENCH_RUN_PARSE json.ctx.len = ArrayCopy(json.ctx.buffer, g_json_data, 0, 0); InitTables(); Sleep(250); // ahora is testeo const ulong a = GetMicrosecondCount(); for(int i = 0; i < 1000; i++) { json.ParseData(); } const ulong b = GetMicrosecondCount(); Print("@", b - a); #else json.Parse(g_json_test_access); CJsonNode root = json.GetRoot(); #ifdef JSONBENCH_RUN_MIX string keys[]; const int n = root["wide_object"].GetKeys(keys); //-- Random TSN::CRandom xo; xo.Seed(JSONBENCH_ACCESO_XHOR_SEED); // init double sump = 0.0, profit = 0.0; long tin = 0; //-- ulong a = GetMicrosecondCount(); for(int i = 0; i < JSONBENCH_TOTAL_ITER_ACCESO; i++) { const string key = keys[xo.RandomInteger(0, n)]; root["wide_object"][key]; } ulong b = GetMicrosecondCount(); Sleep(100); JSONBENCH_ACCES_CALL(JSONBENCH_TAGOP_ACCESO_WIDE) a = GetMicrosecondCount(); for(int i = 0; i < JSONBENCH_TOTAL_ITER_ACCESO; i++) { root["deep_object"]["l1"]["l2"]["l3"]["l4"]["l5"]["l6"]["l7"]["l8"]["l9"]["l10"]["target"].ToString(); } b = GetMicrosecondCount(); Sleep(100); JSONBENCH_ACCES_CALL(JSONBENCH_TAGOP_ACCESO_DEEP) a = GetMicrosecondCount(); for(int i = 0; i < JSONBENCH_TOTAL_ITER_ACCESO; i++) { const int index = xo.RandomInteger(0, 10000); tin += root["large_array"][index].ToInt(0); } b = GetMicrosecondCount(); Sleep(100); JSONBENCH_ACCES_CALL(JSONBENCH_TAGOP_ACCESO_LARGE_ARR) a = GetMicrosecondCount(); for(int k = 0; k < 500; k++) { sump += root["array_of_objects"][k]["price"].ToDouble(0.0); profit += root["array_of_objects"][k]["profit"].ToDouble(0.0); const int s = root["array_of_objects"][k]["tags"].Size(); tin += StringLen(root["array_of_objects"][k]["tags"][k % s].ToString(NULL)); } b = GetMicrosecondCount(); Sleep(100); JSONBENCH_ACCES_CALL(JSONBENCH_TAGOP_ACCESO_MIX) //---- PrintFormat("sump=%.2f profit=%.2f tin=%d ", sump, profit, tin); #else // JSONBENCH_RUN_MIX uchar out[]; root.SerializeExt(out); ulong a = GetMicrosecondCount(); for(int i = 0; i < JSONBENCH_TOTAL_ITER_ACCESO; i++) { root.SerializeExt(out); } ulong b = GetMicrosecondCount(); Sleep(100); JSONBENCH_SER #endif // JSONBENCH_RUN_MIX //--- JSONBENCH_FINISH #endif // JSONBENCH_RUN_PARSE } //+------------------------------------------------------------------+ /* 2026.08.28 08:38:40.961 UtilHeader (EURUSD,H1) [MultiBen& - $[parse|twitter.json|FastJson|1000] 2026.08.28 08:38:47.087 FastJsonBench (EURUSD,H1) @1215738 2026.08.28 08:38:50.291 FastJsonBench (EURUSD,H1) @1214202 2026.08.28 08:38:53.243 FastJsonBench (EURUSD,H1) @1213988 2026.08.28 08:38:56.499 FastJsonBench (EURUSD,H1) @1216412 2026.08.28 08:38:59.496 FastJsonBench (EURUSD,H1) @1240167 2026.08.28 08:39:02.496 FastJsonBench (EURUSD,H1) @1213429 2026.08.28 08:39:05.561 FastJsonBench (EURUSD,H1) @1214146 2026.08.28 08:39:08.572 FastJsonBench (EURUSD,H1) @1236498 2026.08.28 08:39:38.820 UtilHeader (EURUSD,H1) [MultiBen& - %[FastJson] 2026.08.28 08:42:49.658 FastJsonBench (EURUSD,H1) @1246084 2026.10.03 15:20:45.170 FastJsonBench (EURUSD,H1) [acceso-wide] Time: 385 2026.10.03 15:20:45.280 FastJsonBench (EURUSD,H1) [acceso-deep] Time: 2236 2026.10.03 15:20:45.407 FastJsonBench (EURUSD,H1) [acceso-array-large] Time: 16872 2026.10.03 15:20:45.519 FastJsonBench (EURUSD,H1) [acceso-mixed-trading] Time: 2889 2026.10.03 15:20:45.519 FastJsonBench (EURUSD,H1) sump=537.48 profit=-337.50 tin=4927909 2026.10.03 15:20:46.522 FastJsonBench (EURUSD,H1) [acceso-wide] Time: 385 2026.10.03 15:20:46.635 FastJsonBench (EURUSD,H1) [acceso-deep] Time: 2294 2026.10.03 15:20:46.761 FastJsonBench (EURUSD,H1) [acceso-array-large] Time: 16435 2026.10.03 15:20:46.873 FastJsonBench (EURUSD,H1) [acceso-mixed-trading] Time: 2814 2026.10.03 15:20:46.873 FastJsonBench (EURUSD,H1) sump=537.48 profit=-337.50 tin=4927909 */ //+------------------------------------------------------------------+