-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_overhead.c
More file actions
65 lines (47 loc) · 1.87 KB
/
test_overhead.c
File metadata and controls
65 lines (47 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Overhead Test - Measures the profiler's performance overhead
*/
#include "profiler.h"
#include <stdio.h>
#define ITERATIONS 1000000
int main(void) {
profiler_init();
printf("=== Profiler Overhead Test ===\n\n");
/* Measure timer start/stop overhead */
profiler_timer_t overhead_timer;
profiler_timer_start(&overhead_timer, "overhead_measurement");
for (int i = 0; i < ITERATIONS; i++) {
profiler_timer_t t;
profiler_timer_start(&t, "test");
profiler_timer_stop(&t);
}
profiler_timer_stop(&overhead_timer);
uint64_t total_ns = profiler_timer_elapsed_ns(&overhead_timer);
double per_operation_ns = total_ns > 0 ?
(double)total_ns / (double)ITERATIONS : 0.0;
printf("Total iterations: %d\n", ITERATIONS);
printf("Total time: %.3f ms\n", profiler_timer_elapsed_ms(&overhead_timer));
printf("Average overhead per start/stop: %.1f ns\n", per_operation_ns);
/* Test disabled profiler overhead */
profiler_enable(false);
profiler_timer_t disabled_timer;
profiler_timer_start(&disabled_timer, "disabled_measurement");
for (int i = 0; i < ITERATIONS; i++) {
profiler_timer_t t;
profiler_timer_start(&t, "test");
profiler_timer_stop(&t);
}
profiler_timer_stop(&disabled_timer);
/* Enable to print results */
profiler_enable(true);
printf("\nWith profiling disabled:\n");
printf("Total time: %.3f ms\n", profiler_timer_elapsed_ms(&disabled_timer));
uint64_t overhead_ns = profiler_timer_elapsed_ns(&overhead_timer);
uint64_t disabled_ns = profiler_timer_elapsed_ns(&disabled_timer);
if (overhead_ns > 0) {
printf("Overhead reduction: %.1f%%\n",
100.0 * (1.0 - (double)disabled_ns / (double)overhead_ns));
}
profiler_shutdown();
return 0;
}