Created
September 30, 2016 03:01
-
-
Save CristhianMotoche/437af51058f443a7bcd8ea2454d342e1 to your computer and use it in GitHub Desktop.
Determinate times between operations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/time.h> | |
//#include <rand.h> | |
/* Funcion prototipo */ | |
double tiempos(struct timeval , struct timeval ); | |
/* Funcion principal */ | |
int main(){ | |
int x; | |
struct timeval T_START, t_end; | |
// Get first time | |
gettimeofday(&T_START , NULL ); | |
/* ...Do somethingo... */ | |
printf("Insert a number \n>"); | |
scanf("%d",&x); | |
// Get second time | |
gettimeofday(&t_end , NULL ); | |
printf("%f seconds\n", tiempos(T_START, t_end)); | |
return 0; | |
} | |
/* Implementacion de funciones */ | |
double tiempos(struct timeval inicio, struct timeval fin){ | |
double mil_time, sec_time , usec_time; | |
sec_time = fin.tv_sec - inicio.tv_sec; | |
usec_time = fin.tv_usec - inicio.tv_usec; | |
mil_time = ((1000*sec_time)+(usec_time/1000.0))+0.5; | |
// Returns the value in seconds | |
return mil_time/1000.0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment