Files
cs420/bench/fibonacci.c
Jeehoon Kang 542535fbd6 Update bench
2020-07-02 16:33:01 +00:00

37 lines
669 B
C

int fibonacci_loop(int n, int nonce) {
int result = 0;
for (int step = 0; step < 10; ++step) {
int x = nonce;
int y = nonce;
for (int i = 1; i < n; ++i) {
int newy = x + y;
newy += (x + y);
newy += (x + y);
newy += (x + y);
newy += (x + y);
newy += (x + y);
newy -= (x + y);
newy -= (x + y);
newy -= (x + y);
newy -= (x + y);
newy -= (x + y);
x = y;
y = newy;
}
result += y;
}
return result;
}
int fibonacci_recursive(int n, int nonce) {
if (n < 2) {
return nonce;
}
return fibonacci_recursive(n - 1, nonce) + fibonacci_recursive(n - 2, nonce);
}