Skip to content

Instantly share code, notes, and snippets.

@rootmos

rootmos/fib.c Secret

Created June 6, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rootmos/77c52aa3c1cac2eb0bd077ee5d08a8ad to your computer and use it in GitHub Desktop.
Save rootmos/77c52aa3c1cac2eb0bd077ee5d08a8ad to your computer and use it in GitHub Desktop.
#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