mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-15 23:18:48 +00:00
Add benchmark
This commit is contained in:
20
bench/fibonacci.c
Normal file
20
bench/fibonacci.c
Normal file
@@ -0,0 +1,20 @@
|
||||
int fibonacci_loop(int n, int nonce) {
|
||||
int x = nonce;
|
||||
int y = nonce;
|
||||
|
||||
for (int i = 1; i < n; ++i) {
|
||||
int newy = x + y;
|
||||
x = y;
|
||||
y = newy;
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
int fibonacci_recursive(int n, int nonce) {
|
||||
if (n < 2) {
|
||||
return nonce;
|
||||
}
|
||||
|
||||
return fibonacci_recursive(n - 1, nonce) + fibonacci_recursive(n - 2, nonce);
|
||||
}
|
||||
Reference in New Issue
Block a user