This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int fib(int n) { | |
if (n == 1 || n == 2) { | |
return 1; | |
} else { | |
return fib(n-1) + fib(n-2); | |
} | |
} | |
int main() { | |
printf("%d\n", fib(45)); | |
return 0; | |
} | |
/* > gcc -O0 -o fib-c fib.c; /usr/bin/time ./fib-c | |
* 1134903170 | |
* 5.78user 0.00system 0:05.79elapsed 99%CPU (0avgtext+0avgdata 1376maxresident)k | |
* 0inputs+0outputs (0major+64minor)pagefaults 0swaps | |
*/ | |
/* > gcc -O2 -o fib-c fib.c; /usr/bin/time ./fib-c | |
* 1134903170 | |
* 2.39user 0.00system 0:02.39elapsed 99%CPU (0avgtext+0avgdata 1380maxresident)k | |
* 0inputs+0outputs (0major+65minor)pagefaults 0swaps | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment