int main() { int test_val = 100000; struct timeval startv; struct timeval endv; if (gettimeofday(&startv, NULL)){ printf("gettimeofday failed"); return -1; } int v = fibStart(test_val); if (gettimeofday(&endv, NULL)){ printf("gettimeofday failed"); return -1; } long dur = endv.tv_usec - startv.tv_usec; printf("Dynamic Recursive -\nTime: %lu\nValue: %d\n\n", dur, v); struct timeval startIt; struct timeval endIt; if (gettimeofday(&startIt, NULL)){ printf("gettimeofday failed"); return -1; } int v2 = fibIter(test_val); if (gettimeofday(&endIt, NULL)){ printf("gettimeofday failed"); return -1; } long dur2 = endIt.tv_usec - startIt.tv_usec; printf("Iterator -\nTime: %lu\nValue: %d\n\n", dur2, v2); }
int main() { printf("fib(%u) = %lu\n", n, fibIter(n)); return 0; }