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/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/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/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 +