diff --git a/Captura de pantalla de 2020-09-10 10-45-35.png b/Captura de pantalla de 2020-09-10 10-45-35.png new file mode 100644 index 0000000..13ddb95 Binary files /dev/null and b/Captura de pantalla de 2020-09-10 10-45-35.png differ diff --git a/FIBO_TIME.dat b/FIBO_TIME.dat index 721cfc2..647702c 100644 --- a/FIBO_TIME.dat +++ b/FIBO_TIME.dat @@ -1,3 +1,32 @@ +<<<<<<< HEAD +0.000000 0.000000 0.000010 +1.000000 0.000000 0.000000 +2.000000 0.000000 0.000000 +3.000000 0.000000 0.000010 +4.000000 0.000000 0.000020 +5.000000 0.000000 0.000020 +6.000000 0.000000 0.000020 +7.000000 0.000000 0.000030 +8.000000 0.000000 0.000020 +9.000000 0.000000 0.000020 +10.000000 0.000000 0.000030 +11.000000 0.000001 0.000040 +12.000000 0.000001 0.000050 +13.000000 0.000002 0.000040 +14.000000 0.000003 0.000040 +15.000000 0.000005 0.000040 +16.000000 0.000008 0.000060 +17.000000 0.000013 0.000050 +18.000000 0.000020 0.000050 +19.000000 0.000032 0.000050 +20.000000 0.000052 0.000060 +21.000000 0.000082 0.000060 +22.000000 0.000130 0.000060 +23.000000 0.000211 0.000050 +24.000000 0.000341 0.000060 +25.000000 0.000569 0.000060 +||||||| f46ea0f +======= 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 2.000000 0.000000 0.000000 @@ -29,3 +58,4 @@ 28.000000 0.006250 0.000000 29.000000 0.009687 0.000000 30.000000 0.015938 0.000000 +>>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/Sequences.c b/Sequences.c index 9975ea4..4ef9c72 100644 --- a/Sequences.c +++ b/Sequences.c @@ -1,3 +1,52 @@ +<<<<<<< HEAD +// +// Sequences.c +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +#include +#include + +#define Sequences_IMPORT +#include "Sequences.h" + + + +long long int Sequences_sfibo(long long int n){ + long long int sequence_1 = 0, sequence_2 = 1, temp = 0; + int index = 0; + + for (index = 0; index < n; index ++){ + + temp = sequence_2; + sequence_2 = sequence_2 + sequence_1; + sequence_1 = temp; + + } + (n<=0) ? sequence_2 = 0 : (sequence_2 = sequence_1); + + return sequence_2; + +} + + + +long long int Sequences_rfibo(long long int n){ + + if (n == 1){ + return 1; + } + if(n > 1){ + return Sequences_rfibo(n - 1) + Sequences_rfibo(n - 2); + }else{ + return 0; + } + +} +||||||| f46ea0f +======= // // Sequences.h // @@ -85,3 +134,4 @@ long long int Sequences_rfibo(long long int number){ #undef Sequences_IMPORT #undef EXTERN #endif /* Sequences_h */ +>>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/archivos.c b/archivos.c new file mode 100644 index 0000000..9d18bf4 --- /dev/null +++ b/archivos.c @@ -0,0 +1,73 @@ +// +// +// archivos.c +// +// Created by Sergio Medina Galàn and Gustavo Luna Maya on 12/09/2020 +// +// + + +/*Include standard headers*/ +#include +#include +#include + +/*Include modules header we directly invoke here: */ +#include"archivos.h" + +/** + * Initialises a new file pointer identified via its name and mode. + * @param + * name (char *): + * Name of the file + * mode (char *): + * Mode of file to be opened {r, rb, a, ab, w, wb} + * + * @return FILE * opened_file. +*/ +extern FILE * file_new( char * name, char *mode) +{ + FILE *fp; + fp = fopen(name,mode); + return fp; +} + + +/** + * Writes a bidimensional buffer array into a file. + * @param + * file (FILE *): + * Storage file + * columns (size_t ): + * length of the buffer array + * buff [ ][columns] (long double): + * RAM matrix + * rows (size_t): + * width of the storage buffer + * + * @return void. +*/ +extern void file_num_write(FILE * file, size_t columns, long double buff[] [columns], size_t rows) +{ + char linea[10]; + sprintf(linea,"%zu %zu \n",rows,columns); + // fputs (linea, file); + for (size_t i =0; i +#include +#include + +/*Include modules header we directly invoke here: */ +#include"files.h" + +/** + * Initialises a new file pointer identified via its name and mode. + * @param + * name (char *): + * Name of the file + * mode (char *): + * Mode of file to be opened {r, rb, a, ab, w, wb} + * + * @return FILE * opened_file. +*/ +extern FILE * file_new( char * name, char *mode) +{ + FILE *fp; + fp = fopen(name,mode); + return fp; +} + + +/** + * Writes a bidimensional buffer array into a file. + * @param + * file (FILE *): + * Storage file + * columns (size_t ): + * length of the buffer array + * buff [ ][columns] (long double): + * RAM matrix + * rows (size_t): + * width of the storage buffer + * + * @return void. +*/ +extern void file_num_write(FILE * file, size_t columns, long double buff[] [columns], size_t rows) +{ + char linea[10]; + sprintf(linea,"%zu %zu \n",rows,columns); + // fputs (linea, file); + for (size_t i =0; i + +#ifdef files_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + + +/* files.h -- Function prototypes */ + +/** + * Instanciates a new file pointer identified via its name and mode. + * @param + * name (char *): + * Name of the file + * mode (char *): + * Mode of file to be opened {r, rb, a, ab, w, wb} + * + * @return FILE * opened_file. +*/ +EXTERN FILE * file_new(char *name, char *mode); + + + +/** + * Writes a bidimensional buffer array into a file. + * @param + * file (FILE *): + * Storage file + * columns (size_t ): + * length of the buffer array + * buff [ ][columns] (long double): + * RAM matrix + * rows (size_t): + * width of the storage buffer + * + * @return void. +*/ + +EXTERN void file_num_write(FILE * file, size_t columns, long double buff[] [columns], size_t rows); + +#undef files_IMPORT +#undef EXTERN + + + +#endif /* files_h */ diff --git a/archivos.h~ b/archivos.h~ new file mode 100644 index 0000000..7ddc38b --- /dev/null +++ b/archivos.h~ @@ -0,0 +1,58 @@ +// +// files.h +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +#ifndef files_h +#define files_h + +#include + +#ifdef files_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + + +/* files.h -- Function prototypes */ + +/** + * Instanciates a new file pointer identified via its name and mode. + * @param + * name (char *): + * Name of the file + * mode (char *): + * Mode of file to be opened {r, rb, a, ab, w, wb} + * + * @return FILE * opened_file. +*/ +EXTERN FILE * file_new(char *name, char *mode); + + + +/** + * Writes a bidimensional buffer array into a file. + * @param + * file (FILE *): + * Storage file + * columns (size_t ): + * length of the buffer array + * buff [ ][columns] (long double): + * RAM matrix + * rows (size_t): + * width of the storage buffer + * + * @return void. +*/ + +EXTERN void file_num_write(FILE * file, size_t columns, long double buff[] [columns], size_t rows); + +#undef files_IMPORT +#undef EXTERN + + + +#endif /* files_h */ diff --git a/files.c b/files.c index dd86bdb..96d0a32 100644 --- a/files.c +++ b/files.c @@ -1,3 +1,45 @@ +<<<<<<< HEAD +// +// files.c +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +#include + +#define files_IMPORT +#include "files.h" + + + + + +FILE * file_new(char *name, char *mode){ + FILE * my_file = NULL; + + my_file = fopen(name, mode); + + if (my_file == NULL){ + puts("FILE OPEN ERROR"); + return NULL; + }else + return my_file; +} + + +void file_num_write(FILE * file,size_t columns, long double buff[][columns], size_t rows){ + size_t row, column = 0; + + for(row = 0; row < rows; row ++){ + for(column = 0; column < columns; column ++){ + fprintf(file, "%Lf\t", buff[row][column]); + } + fprintf(file, "\n"); + } +} +||||||| f46ea0f +======= // // files.h // @@ -76,4 +118,5 @@ void file_num_write(FILE * file, size_t columns, long double buff[][columns], si -#endif /* files_h */ \ No newline at end of file +#endif /* files_h */ +>>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/funcionesfibo.c b/funcionesfibo.c new file mode 100644 index 0000000..2c36fe7 --- /dev/null +++ b/funcionesfibo.c @@ -0,0 +1,50 @@ +// +// +// funcionesfibo.c +// +// Created by Sergio Medina Galàn and Gustavo Luna Maya on 12/09/2020 +// +// + + +/*Inlcude standard headers*/ +#include + +/*Inlude modules header we directly invoke here: */ +#include "funcionesfibo.h" + + +/** + * Returns the value of the fibonacci sequence at index n calculated recursively + * @param + * n (long long int): + * Index of the fibonacci sequence + * @return long long int value +*/ +extern long long int Sequences_rfibo(long long int n) +{ + if (n==0 || n ==1) + return n; + else + return Sequences_rfibo(n-2) + Sequences_rfibo(n-1); + } + +/** + * Returns the value of the fibonacci sequence at index n calculated sequentially + * @param + * n (long long int): + * Index of the fibonacci sequence + * @return long long int value +*/ +extern long long int Sequences_sfibo(long long int n) +{ + long long int p=0,s=1,u; + int i; + for(i=0; i<=n;i++){ + u=p+s; + p=s; + s=u; + + } + return u; +} diff --git a/funcionesfibo.c~ b/funcionesfibo.c~ new file mode 100644 index 0000000..eb82119 --- /dev/null +++ b/funcionesfibo.c~ @@ -0,0 +1,50 @@ +// +// +// Sequences.c +// +// Created by Sergio Medina Galàn and Gustavo Luna Maya on 12/09/2020 +// +// + + +/*Inlcude standard headers*/ +#include + +/*Inlude modules header we directly invoke here: */ +#include "Sequences.h" + + +/** + * Returns the value of the fibonacci sequence at index n calculated recursively + * @param + * n (long long int): + * Index of the fibonacci sequence + * @return long long int value +*/ +extern long long int Sequences_rfibo(long long int n) +{ + if (n==0 || n ==1) + return n; + else + return Sequences_rfibo(n-2) + Sequences_rfibo(n-1); + } + +/** + * Returns the value of the fibonacci sequence at index n calculated sequentially + * @param + * n (long long int): + * Index of the fibonacci sequence + * @return long long int value +*/ +extern long long int Sequences_sfibo(long long int n) +{ + long long int p=0,s=1,u; + int i; + for(i=0; i<=n;i++){ + u=p+s; + p=s; + s=u; + + } + return u; +} diff --git a/funcionesfibo.h b/funcionesfibo.h new file mode 100644 index 0000000..11d5bc1 --- /dev/null +++ b/funcionesfibo.h @@ -0,0 +1,44 @@ +// +// funcionesfibo.h +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +#ifndef Sequences_h +#define Sequences_h + +#include + +#ifdef Sequences_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + + +/* Sequences.h -- Function prototypes */ + +/** + * Returns the value of the fibonacci sequence at index n calculated sequentially + * @param + * n (long long int): + * Index of the fibonacci sequence + * @return long long int value +*/ +EXTERN long long int Sequences_sfibo(long long int n); + + +/** + * Returns the value of the fibonacci sequence at index n calculated recursively + * @param + * n (long long int): + * Index of the fibonacci sequence + * @return long long int value +*/ +EXTERN long long int Sequences_rfibo(long long int n); + + +#undef Sequences_IMPORT +#undef EXTERN +#endif /* Sequences_h */ diff --git a/funcionesfibo.h~ b/funcionesfibo.h~ new file mode 100644 index 0000000..dac8ae0 --- /dev/null +++ b/funcionesfibo.h~ @@ -0,0 +1,44 @@ +// +// Sequences.h +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +#ifndef Sequences_h +#define Sequences_h + +#include + +#ifdef Sequences_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + + +/* Sequences.h -- Function prototypes */ + +/** + * Returns the value of the fibonacci sequence at index n calculated sequentially + * @param + * n (long long int): + * Index of the fibonacci sequence + * @return long long int value +*/ +EXTERN long long int Sequences_sfibo(long long int n); + + +/** + * Returns the value of the fibonacci sequence at index n calculated recursively + * @param + * n (long long int): + * Index of the fibonacci sequence + * @return long long int value +*/ +EXTERN long long int Sequences_rfibo(long long int n); + + +#undef Sequences_IMPORT +#undef EXTERN +#endif /* Sequences_h */ diff --git a/time_test b/time_test new file mode 100755 index 0000000..d650812 Binary files /dev/null and b/time_test differ diff --git a/time_test_fibo.c b/time_test_fibo.c index 62df120..75c202b 100644 --- a/time_test_fibo.c +++ b/time_test_fibo.c @@ -1,3 +1,72 @@ +<<<<<<< HEAD +// +// time_test_fibo.c +// +// +// Created by Cesar Angeles on 07/09/2020. +// + + + +#include +#include + + + +#include "Sequences.h" +#include "files.h" +#include "time_test_fibo.h" + +int main(void){ + + long long int value = 0; + int index = 0; + clock_t start, stop; + double cpu_time = 0; + double mean = 0; + FILE * record = NULL; + long double buffer[OBSERVATIONS][VALUES] = {0}; + size_t obs = 0; + + record = file_new("FIBO_TIME.dat","w"); + + //puts("Enter n fibo value:"); + //scanf("%lld", &value); + + printf("%lld\t", value); + + for (obs = 0; obs < OBSERVATIONS; obs ++){ + printf("%zu\n",obs); + + + start = clock(); + for (index = 0; index <= STATISTIC; index ++){ + Sequences_rfibo(obs); + } + stop = clock(); + + cpu_time = ((double)(stop-start)) /CLOCKS_PER_SEC / STATISTIC; + buffer[obs][INDEX] = obs; + buffer[obs][RECURSIVE] = cpu_time; + printf("Recursive Fibo time %f s\t", cpu_time); + + start = clock(); + for (index = 0; index <= STATISTIC; index ++){ + Sequences_sfibo(obs); + } + stop = clock(); + + cpu_time = ((double)(stop-start)) /CLOCKS_PER_SEC / STATISTIC; + buffer[obs][ITERATIVE] = cpu_time*1e3; + printf("Sequential Fibo time %f ms\n", cpu_time*1e3); + } + + file_num_write(record, VALUES, buffer, OBSERVATIONS); + fclose(record); + +} +||||||| f46ea0f +======= // // time_test_fibo.c // @@ -57,4 +126,5 @@ int main(void){ file_num_write(record, VALUES, buffer, OBSERVATIONS); fclose(record); -} \ No newline at end of file +} +>>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/time_test_fibo.h b/time_test_fibo.h index fe0dbf6..42699e6 100644 --- a/time_test_fibo.h +++ b/time_test_fibo.h @@ -1,3 +1,30 @@ +<<<<<<< HEAD +// +// time_test_fibo.h +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +#ifndef time_test_fibo_h +#define time_test_fibo_h + +#include +#include "files.h" + +#define STATISTIC 100.0 +#define OBSERVATIONS 26 +#define VALUES 3 + +typedef enum{ + INDEX, + RECURSIVE, + ITERATIVE +}TYPE; + +#endif /* time_test_fibo_h */ +||||||| f46ea0f +======= // // time_test_fibo.h // @@ -21,4 +48,5 @@ typedef enum{ ITERATIVE }TYPE; -#endif /* time_test_fibo_h */ \ No newline at end of file +#endif /* time_test_fibo_h */ +>>>>>>> e94102e9b652f269c770d77c8267559b161b52fd diff --git a/timetest.c b/timetest.c new file mode 100644 index 0000000..89db07b --- /dev/null +++ b/timetest.c @@ -0,0 +1,60 @@ +// +// time_test_fibo.c +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +/*Include standard headers*/ +#include +#include +#include + +/*Include modules header we directly invoke here: */ +#include "funcionesfibo.h" +#include "archivos.h" +#include "timetest.h" + +/*The function main */ +int main(void){ + + long long int value =0; + int index =0; + clock_t start, stop; + double cput =0; + double mean =0; + FILE * record = NULL; + long double buffer [OBSERVATIONS][VALUES] ={0}; + size_t obs =0; + + record = file_new("FIBO_TIME.dat","w"); + + for(obs=0; obs < OBSERVATIONS; obs++){ + printf(" %zu\n",obs); + start = clock(); + for( index=0; index <= 100; index++){ + Sequences_rfibo(obs); + } + stop = clock(); + + cput= ((double)(stop-start)) /CLOCKS_PER_SEC /100; + buffer[obs][0] = obs; + buffer[obs][1] = cput; + printf("Recursiva %f s \t", cput); + + + start = clock(); + for( index=0; index <= 100; index++){ + Sequences_sfibo(obs); + } + stop = clock(); + + cput= ((double)(stop-start)) /CLOCKS_PER_SEC /100; + + buffer[obs][2] = cput*1e3; + printf("Secuencial %f ms \t", cput*1e3); + } + file_num_write(record, VALUES, buffer, OBSERVATIONS); + fclose(record); +} + diff --git a/timetest.c~ b/timetest.c~ new file mode 100644 index 0000000..f8a1af1 --- /dev/null +++ b/timetest.c~ @@ -0,0 +1,60 @@ +// +// time_test_fibo.c +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +/*Include standard headers*/ +#include +#include +#include + +/*Include modules header we directly invoke here: */ +#include "Sequences.h" +#include "files.h" +#include "time_test_fibo.h" + +/*The function main */ +int main(void){ + + long long int value =0; + int index =0; + clock_t start, stop; + double cput =0; + double mean =0; + FILE * record = NULL; + long double buffer [OBSERVATIONS][VALUES] ={0}; + size_t obs =0; + + record = file_new("FIBO_TIME.dat","w"); + + for(obs=0; obs < OBSERVATIONS; obs++){ + printf(" %zu\n",obs); + start = clock(); + for( index=0; index <= 100; index++){ + Sequences_rfibo(obs); + } + stop = clock(); + + cput= ((double)(stop-start)) /CLOCKS_PER_SEC /100; + buffer[obs][0] = obs; + buffer[obs][1] = cput; + printf("Recursiva %f s \t", cput); + + + start = clock(); + for( index=0; index <= 100; index++){ + Sequences_sfibo(obs); + } + stop = clock(); + + cput= ((double)(stop-start)) /CLOCKS_PER_SEC /100; + + buffer[obs][2] = cput*1e3; + printf("Secuencial %f ms \t", cput*1e3); + } + file_num_write(record, VALUES, buffer, OBSERVATIONS); + fclose(record); +} + diff --git a/timetest.h b/timetest.h new file mode 100644 index 0000000..d6e3ddd --- /dev/null +++ b/timetest.h @@ -0,0 +1,20 @@ +// +// time_test_fibo.h +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +#ifndef time_test_fibo_h +#define time_test_fibo_h + +#include +#include "archivos.h" + + +#define STATISTIC +#define OBSERVATIONS 25 +#define VALUES 3 + +#endif + diff --git a/timetest.h~ b/timetest.h~ new file mode 100644 index 0000000..16d4688 --- /dev/null +++ b/timetest.h~ @@ -0,0 +1,20 @@ +// +// time_test_fibo.h +// +// +// Created by Cesar Angeles on 07/09/2020. +// + +#ifndef time_test_fibo_h +#define time_test_fibo_h + +#include +#include "files.h" + + +#define STATISTIC +#define OBSERVATIONS 25 +#define VALUES 3 + +#endif +