Jump to content

Tempo Execuçao Programa


sinomen
 Share

Recommended Posts

Boa Tarde,

Estava a tentar o tempo de execuçao de uma funçao em C, mas tou com dificuldades. Fui aconselhado a usar time(&t) e difftime(t1, t2) para medir os tempos. Mas no exemplo abaixo onde faço incrementos aquela variavel i, nao deveria dar alguns milissegundos de tempo de execuçao ? Obtenho 0 segundos. Peço desculpa se a pergunta é estupida. Agradeço uma ajuda. Obrigado.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main () {

int i=0;
time_t start_t, end_t;
double diff_t;
printf("Starting of the program...\n");
time(&start_t);

while(i<10000000){
i++;
}

time(&end_t);
diff_t = difftime(end_t, start_t);
printf("Execution time = %f\n", diff_t);
return(0);

}
Edited by thoga31
GeSHi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.