Add gprof test code

This commit is contained in:
Takumi Sueda
2026-04-13 13:32:09 +09:00
parent a17bbf6b14
commit d48949419e
5 changed files with 77 additions and 0 deletions

31
gprof/profile.c Normal file
View File

@@ -0,0 +1,31 @@
#include <stdio.h>
int __attribute__((noinline)) fibonacci(int n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
void __attribute__((noinline)) dummy_work(int count) {
volatile int sum = 0;
for (int i = 0; i < count; i++) {
sum += i;
}
}
void __attribute__((noinline)) heavy_logic() {
for (int i = 0; i < 5; i++) {
// It will take up to a few sec
printf("Computing fib(30)... iteration %d\n", i);
fibonacci(30);
}
}
int main(int argc, char* argv[]) {
printf("--- Profiling Test Start ---\n");
heavy_logic();
dummy_work(1000);
printf("--- Profiling Test End ---\n");
return 0;
}