Measure overhead by comparing with and without CTRACK
| 366 | |
| 367 | // Measure overhead by comparing with and without CTRACK |
| 368 | std::tuple<double, double, double> measure_overhead() |
| 369 | { |
| 370 | std::cout << "\n=== Measuring Overhead ===" << std::endl; |
| 371 | |
| 372 | const size_t overhead_events = 1'000'000; // 1M events for overhead test |
| 373 | size_t events_per_thread = overhead_events / g_config.thread_count; |
| 374 | |
| 375 | // Measure without CTRACK |
| 376 | auto start_no_track = std::chrono::high_resolution_clock::now(); |
| 377 | { |
| 378 | std::vector<std::thread> threads; |
| 379 | std::atomic<bool> start_flag{false}; |
| 380 | |
| 381 | for (size_t i = 0; i < g_config.thread_count; ++i) |
| 382 | { |
| 383 | threads.emplace_back(benchmark_worker_no_track, events_per_thread, std::ref(start_flag)); |
| 384 | } |
| 385 | |
| 386 | start_flag = true; |
| 387 | |
| 388 | for (auto &t : threads) |
| 389 | { |
| 390 | t.join(); |
| 391 | } |
| 392 | } |
| 393 | auto end_no_track = std::chrono::high_resolution_clock::now(); |
| 394 | auto duration_no_track = std::chrono::duration_cast<std::chrono::microseconds>(end_no_track - start_no_track).count(); |
| 395 | |
| 396 | // Clear tracking data by getting and discarding results |
| 397 | ctrack::result_as_string(); |
| 398 | |
| 399 | // Measure with CTRACK |
| 400 | auto start_track = std::chrono::high_resolution_clock::now(); |
| 401 | { |
| 402 | std::vector<std::thread> threads; |
| 403 | std::atomic<bool> start_flag{false}; |
| 404 | |
| 405 | for (size_t i = 0; i < g_config.thread_count; ++i) |
| 406 | { |
| 407 | threads.emplace_back(benchmark_worker, events_per_thread, std::ref(start_flag)); |
| 408 | } |
| 409 | |
| 410 | start_flag = true; |
| 411 | |
| 412 | for (auto &t : threads) |
| 413 | { |
| 414 | t.join(); |
| 415 | } |
| 416 | } |
| 417 | auto end_track = std::chrono::high_resolution_clock::now(); |
| 418 | auto duration_track = std::chrono::duration_cast<std::chrono::microseconds>(end_track - start_track).count(); |
| 419 | |
| 420 | double overhead_percent = ((double)(duration_track - duration_no_track) / duration_no_track) * 100.0; |
| 421 | double overhead_ms = (duration_track - duration_no_track) / 1000.0; // Convert microseconds to milliseconds |
| 422 | double overhead_ns_per_event = ((duration_track - duration_no_track) * 1000.0) / overhead_events; // nanoseconds per event |
| 423 | |
| 424 | if (g_config.verbose) |
| 425 | { |
no test coverage detected