| 473 | } |
| 474 | |
| 475 | int test_large_json_profiling() { |
| 476 | printf("\n\n"); |
| 477 | printf("================================================================================\n"); |
| 478 | printf("LOADING LARGE JSON FILE\n"); |
| 479 | printf("================================================================================\n"); |
| 480 | |
| 481 | // Initialize FileSystem for testing |
| 482 | FileSystem fs; |
| 483 | FsImplPtr fsImpl = make_sdcard_filesystem(0); |
| 484 | if (!fs.begin(fsImpl)) { |
| 485 | printf("❌ ERROR: Failed to initialize test filesystem\n"); |
| 486 | return 1; // Failure |
| 487 | } |
| 488 | |
| 489 | // Open and read the JSON file |
| 490 | ifstream fh = fs.openRead("tests/profile/benchmark_1mb.json"); |
| 491 | if (!fh.is_open()) { |
| 492 | printf("⚠️ WARNING: Could not open tests/profile/benchmark_1mb.json\n"); |
| 493 | printf(" Skipping large JSON memory profile test.\n"); |
| 494 | printf(" Download it with: curl -o tests/profile/benchmark_1mb.json https://microsoftedge.github.io/Demos/json-dummy-data/1MB.json\n"); |
| 495 | return 0; // Skip, not a failure |
| 496 | } |
| 497 | |
| 498 | // Read file contents |
| 499 | fl::size file_size = fh.size(); |
| 500 | fl::string large_json; |
| 501 | large_json.resize(file_size); |
| 502 | fl::size bytes_read = fh.read(reinterpret_cast<u8*>(&large_json[0]), file_size); |
| 503 | fh.close(); |
| 504 | |
| 505 | if (bytes_read != file_size) { |
| 506 | printf("❌ ERROR: Read %zu bytes but expected %zu bytes\n", bytes_read, file_size); |
| 507 | return 1; // Failure |
| 508 | } |
| 509 | |
| 510 | printf("✓ Loaded %zu bytes (%.2f KB)\n\n", bytes_read, bytes_read / 1024.0); |
| 511 | |
| 512 | // Run memory profiling on large JSON |
| 513 | profile_json_memory("LARGE JSON MEMORY PROFILE (1MB Real-World)", large_json); |
| 514 | |
| 515 | return 0; // Success |
| 516 | } |
| 517 | |
| 518 | // ============================================================================ |
| 519 | // MAIN ENTRY POINT |