Sul forum trovate la risposta ai vostri problemi... ma sono buono e vi posto il codice
codice:
#ifdef _WIN32
#include <windows.h>
static LARGE_INTEGER _tstart, _tend;
static LARGE_INTEGER freq;
void tstart(void){
static int first = 1;
if(first){
QueryPerformanceFrequency(&freq);
first = 0;
}
QueryPerformanceCounter(&_tstart);
}
void tend(void){
QueryPerformanceCounter(&_tend);
}
double tval(){
return ((double)_tend.QuadPart - (double)_tstart.QuadPart)/((double)freq.QuadPart);
}
#else
#include <sys/time.h>
static struct timeval _tstart, _tend;
static struct timezone tz;
void tstart(void){
gettimeofday(&_tstart, &tz);
}
void tend(void){
gettimeofday(&_tend,&tz);
}
double tval(){
typedef signed long s;
s t1, t2;
t1 = (s)_tstart.tv_sec + (s)_tstart.tv_usec/(1000*1000);
t2 = (s)_tend.tv_sec + (s)_tend.tv_usec/(1000*1000);
return t2-t1;
}
#endif
prima di far partire la porzione di codice da cronometrare chiamate
tstart();
quando dovete fermare il tempo chiamate
tend();
e subito dopo
double tempo=tval()