-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfib_test.cpp
59 lines (50 loc) · 1.28 KB
/
fib_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// fib_test.cpp
//
#include "fib_test.hpp"
int fib_func(int fib_type, int n) {
if (fib_type == 1) {
return fib_recursive(n);
}
else if (fib_type == 2) {
return fib_iterative(n);
}
else if (fib_type == 3) {
return fib_matrix(n);
}
else if (fib_type == 4) {
return fib_recursive_mod(n);
}
else if (fib_type == 5) {
return fib_iterative_mod(n);
}
else if (fib_type == 6) {
return fib_matrix_mod(n);
}
else {
return 0;
}
}
void fib_test_pow2(int end_val, int fib_type) {
clock_t start, end;
// test powers of 2, from 2^0 to 2^30
for (int j = 0; j < end_val; j++) {
int n_pow = (int)pow(2, j);
start = clock();
unsigned int n = fib_func(fib_type, n_pow);
end = clock();
double time_spent = (double)(end - start) / CLOCKS_PER_SEC;
printf("%d,%d,%f\n", n_pow, n, time_spent);
}
}
void fib_test_n(int end_val, int fib_type) {
clock_t start, end;
int n;
for (int i = 0; i < end_val; i++) {
start = clock();
n = fib_func(fib_type, i);
end = clock();
double time_spent = (double)(end - start) / CLOCKS_PER_SEC;
printf("%d,%d,%f\n", i, n, time_spent);
}
}