forked from CesarAng28/TDA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrincipal.c
More file actions
76 lines (52 loc) · 1.63 KB
/
Principal.c
File metadata and controls
76 lines (52 loc) · 1.63 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include"Sequences.h"
#include"files.h"
#define AMOUNT 30
#define INDEX 0
#define ITERATIVE 1
#define RECURSIVE 2
#define STATISTIC 1000.0
#define COLUMNS 3
int main(void)
{
long long int number;
size_t index;
long long int result = 0;
clock_t start, stop;
double cpu_time = 0;
size_t statistic = 0;
long double buffer_matrix[AMOUNT][COLUMNS] = {0};
FILE * Archivo = NULL;
Archivo = file_new("TIME_FIBONACCI.dat","w");
for(index = 0;index < AMOUNT;index++)
{
printf("%zu\n",index+1);
/*Realizamos el calculo iterativamente*/
start = clock();
for (statistic = 0; statistic < STATISTIC; statistic ++){
result = Sequences_sfibo(index);
}
stop = clock();
printf("Result: %lld ", result);
cpu_time = ((double)(stop-start)) / CLOCKS_PER_SEC/STATISTIC;
/*Guardamos el los valores en la matriz*/
buffer_matrix[index][INDEX] = index;
buffer_matrix[index][ITERATIVE] = cpu_time*1e3;
printf("\nSequential Fibo Time: %f ms\n",cpu_time*1e3);
/*Realizamos el calculo recursivamente*/
start = clock();
Sequences_rfibo(index);
stop = clock();
cpu_time = ((double)(stop-start))/CLOCKS_PER_SEC;
/*Guardamos el los valores en la matriz*/
buffer_matrix[index][RECURSIVE] = cpu_time;
printf("Recursive Fibo Time: %f s\n",cpu_time);
printf("\n\n");
}
/*Para terminar, llamamos a nuestra funcion que escribira la matriz en el archivo.*/
file_num_write(Archivo,COLUMNS,buffer_matrix,AMOUNT);
printf("\n");
return 0;
}