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

Function run_benchmark

tests/profile/benchmark_json_parsers.cpp:36–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36void run_benchmark(const char* test_name, const fl::string& json_data, int iterations, bool& success) {
37 printf("\n");
38 printf("================================================================================\n");
39 printf("%s\n", test_name);
40 printf("================================================================================\n");
41 printf("JSON size: %zu bytes (%.2f KB)\n", json_data.size(), json_data.size() / 1024.0);
42 printf("Iterations: %d\n", iterations);
43 printf("\n");
44
45 // Benchmark Legacy parse()
46 double parse1_time = benchmark_microseconds([&]() {
47 json result = json::parse(json_data);
48 if (result.is_null()) {
49 success = false;
50 }
51 volatile bool valid = !result.is_null();
52 (void)valid;
53 }, iterations);
54
55 // Benchmark Custom parse2()
56 double parse2_time = benchmark_microseconds([&]() {
57 json result = json::parse(json_data);
58 if (result.is_null()) {
59 success = false;
60 }
61 volatile bool valid = !result.is_null();
62 (void)valid;
63 }, iterations);
64
65 // Results
66 printf("Performance Results:\n");
67 printf(" Legacy parse(): %.2f µs/parse\n", parse1_time);
68 printf(" Custom parse2(): %.2f µs/parse\n", parse2_time);
69 printf("\n");
70
71 // Comparison
72 printf("================================ COMPARISON =====================================\n");
73
74 double speedup = parse1_time / parse2_time;
75 double ratio = parse2_time / parse1_time;
76
77 if (parse2_time < parse1_time) {
78 printf("✓ parse2() is FASTER: %.2fx speedup (%.1f%% of parse() time)\n",
79 speedup, ratio * 100.0);
80 printf(" Time saved: %.2f µs per parse (%.1f%% reduction)\n",
81 parse1_time - parse2_time, (1.0 - ratio) * 100.0);
82 } else {
83 printf("✗ parse2() is SLOWER: %.2fx slowdown (%.1f%% of parse() time)\n",
84 1.0 / speedup, ratio * 100.0);
85 printf(" Extra time: %.2f µs per parse (%.1f%% increase)\n",
86 parse2_time - parse1_time, (ratio - 1.0) * 100.0);
87 }
88
89 // Throughput
90 double throughput1_mbps = (json_data.size() / parse1_time) * 1.0; // bytes/µs = MB/s
91 double throughput2_mbps = (json_data.size() / parse2_time) * 1.0;
92
93 printf("\n");

Callers 2

run_small_benchmarkFunction · 0.70
run_large_benchmarkFunction · 0.70

Calls 4

printfFunction · 0.85
benchmark_microsecondsFunction · 0.70
sizeMethod · 0.45
is_nullMethod · 0.45

Tested by

no test coverage detected