#include #include #include static uint64_t usecs() { struct timeval tv; gettimeofday(&tv, NULL); return ((uint64_t)tv.tv_sec * 1000000) + tv.tv_usec; } int ifib(int x) { if(x <= 2) return 1; int a = 1, b = 1, c; x -= 2; while(x) { c = a + b; b = a; a = c; x--; } return c; } int fib(int x) { if(x <= 2) return 1; return fib(x - 1) + fib(x - 2); } int main(int argc, char *argv[]) { int n = argc > 1? atol(argv[1]) : 24; int i; uint64_t start = usecs(); for(i = 0; i < 1000; i++) { int r = ifib(n); } uint64_t end = usecs(); printf("Time: %llu us\n", end - start); }