MCPcopy Create free account
hub / github.com/FastLED/FastLED / profile_json_memory

Function profile_json_memory

tests/profile/json_memory_profile.cpp:318–415  ·  view source on GitHub ↗

Helper to run memory profiling on a JSON string

Source from the content-addressed store, hash-verified

316
317// Helper to run memory profiling on a JSON string
318void profile_json_memory(const char* test_name, const fl::string& json_data) {
319 printf("\n\n");
320 printf("================================================================================\n");
321 printf("%s\n", test_name);
322 printf("================================================================================\n");
323 printf("JSON size: %zu bytes (%.2f KB)\n", json_data.size(), json_data.size() / 1024.0);
324 printf("\n");
325
326#ifdef _WIN32
327 init_real_allocators();
328#endif
329
330 // Baseline: Measure overhead of tracking itself
331 g_tracking_enabled = false;
332 {
333 json warmup = json::parse(json_data);
334 (void)warmup;
335 }
336
337 // Test 1: Legacy parse()
338 g_stats.reset();
339 g_tracking_enabled = true;
340
341 size_t parse1_peak = 0;
342 size_t parse1_allocs = 0;
343 {
344 json result1 = json::parse(json_data);
345 if (result1.is_null()) {
346 printf("❌ ERROR: Legacy parse() failed\n");
347 g_tracking_enabled = false;
348 return;
349 }
350
351 parse1_peak = g_stats.peak_bytes.load();
352 parse1_allocs = g_stats.alloc_count.load();
353 }
354
355 g_tracking_enabled = false;
356 g_stats.print_stats("Legacy parse()");
357
358 // Test 2: Custom parse2()
359 g_stats.reset();
360 g_tracking_enabled = true;
361
362 size_t parse2_peak = 0;
363 size_t parse2_allocs = 0;
364 {
365 json result2 = json::parse2(json_data);
366 if (result2.is_null()) {
367 printf("❌ ERROR: Custom parse2() failed\n");
368 g_tracking_enabled = false;
369 return;
370 }
371
372 parse2_peak = g_stats.peak_bytes.load();
373 parse2_allocs = g_stats.alloc_count.load();
374 }
375

Callers 2

Calls 7

printfFunction · 0.85
init_real_allocatorsFunction · 0.85
print_statsMethod · 0.80
sizeMethod · 0.45
resetMethod · 0.45
is_nullMethod · 0.45
loadMethod · 0.45

Tested by 2