JsonParserByLeo/Test/Ben/FastJsonBench.mq5

158 lines
5.2 KiB
MQL5
Raw Permalink Normal View History

2026-08-28 08:28:39 -05:00
//+------------------------------------------------------------------+
//| 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
2026-08-28 09:42:51 -05:00
//#define JSONBENCH_RUN_PARSE
2026-08-28 08:28:39 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#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"
2026-08-28 09:42:51 -05:00
// FastJson
#define LIBNAME "FastJson"
2026-08-28 08:28:39 -05:00
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
CJson json;
2026-08-28 09:42:51 -05:00
#ifdef JSONBENCH_RUN_PARSE
2026-08-28 08:28:39 -05:00
json.ctx.len = StringToCharArray(g_json_data, json.ctx.buffer);
InitTables();
Sleep(250);
// ahora is testeo
const ulong a = GetMicrosecondCount();
for(int i = 0; i < 1000; i++)
{
json.ParseData();
}
const ulong b = GetMicrosecondCount();
2026-08-28 09:42:51 -05:00
Print("@", b - a);
#else
json.Parse(g_json_test_access);
CJsonNode root = json.GetRoot();
string keys[];
const int n = root["wide_object"].GetKeys(keys);
//-- Random
Xoshiro256 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);
tin += root["array_of_objects"][k]["tags"].Size();
}
b = GetMicrosecondCount();
Sleep(100);
JSONBENCH_ACCES_CALL(JSONBENCH_TAGOP_ACCESO_MIX)
//----
PrintFormat("sump=%.2f profit=%.2f tin=%d ", sump, profit, tin);
//---
JSONBENCH_FINISH
#endif // JSONBENCH_RUN_PARSE
2026-08-28 08:28:39 -05:00
}
//+------------------------------------------------------------------+
2026-08-28 09:42:51 -05:00
/*
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.08.28 08:43:28.971 FastJsonBench (EURUSD,H1) [acceso-wide] Time: 376
2026.08.28 08:43:29.082 FastJsonBench (EURUSD,H1) [acceso-deep] Time: 2279
2026.08.28 08:43:29.210 FastJsonBench (EURUSD,H1) [acceso-array-large] Time: 18251
2026.08.28 08:43:29.319 FastJsonBench (EURUSD,H1) [acceso-mixed-trading] Time: 2605
2026.08.28 08:43:29.319 FastJsonBench (EURUSD,H1) sump=537.48 profit=-337.50 tin=4925578
2026.08.28 08:43:31.120 FastJsonBench (EURUSD,H1) [acceso-wide] Time: 372
2026.08.28 08:43:31.232 FastJsonBench (EURUSD,H1) [acceso-deep] Time: 2280
2026.08.28 08:43:31.359 FastJsonBench (EURUSD,H1) [acceso-array-large] Time: 18477
2026.08.28 08:43:31.471 FastJsonBench (EURUSD,H1) [acceso-mixed-trading] Time: 2069
2026.08.28 08:43:31.471 FastJsonBench (EURUSD,H1) sump=537.48 profit=-337.50 tin=4925578
2026.08.28 08:43:38.648 FastJsonBench (EURUSD,H1) [acceso-wide] Time: 372
2026.08.28 08:43:38.759 FastJsonBench (EURUSD,H1) [acceso-deep] Time: 2441
2026.08.28 08:43:38.887 FastJsonBench (EURUSD,H1) [acceso-array-large] Time: 18497
2026.08.28 08:43:39.000 FastJsonBench (EURUSD,H1) [acceso-mixed-trading] Time: 2081
2026.08.28 08:43:39.000 FastJsonBench (EURUSD,H1) sump=537.48 profit=-337.50 tin=4925578
*/