-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample3_stats.c
More file actions
47 lines (35 loc) · 1.01 KB
/
example3_stats.c
File metadata and controls
47 lines (35 loc) · 1.01 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
/**
* Example 3: Statistics Collection
*
* Demonstrates aggregated statistics over multiple measurements
*/
#include "profiler.h"
#include <stdlib.h>
#include <unistd.h>
void simulate_work(int ms) {
usleep(ms * 1000);
}
void run_benchmark(int iterations) {
profiler_stats_t stats;
profiler_stats_init(&stats, "benchmark");
printf("Running %d iterations...\n", iterations);
for (int i = 0; i < iterations; i++) {
profiler_timer_t timer;
profiler_timer_start(&timer, "iteration");
/* Simulate variable workload */
int work_time = 5 + (rand() % 15);
simulate_work(work_time);
profiler_timer_stop(&timer);
profiler_stats_add(&stats, profiler_timer_elapsed_ns(&timer));
}
printf("\n");
profiler_stats_print(&stats);
}
int main(void) {
profiler_init();
srand(12345);
printf("=== Example 3: Statistics Collection ===\n\n");
run_benchmark(10);
profiler_shutdown();
return 0;
}