This function is not mine, I took it from the Internet. Here's the code:
Code:
#include <sys/time.h>
#include <stdio.h>
struct timeval tv1,tv2,dtv;
struct timezone tz;
void time_start() { gettimeofday(&tv1, &tz); }
long time_stop()
{ gettimeofday(&tv2, &tz);
dtv.tv_sec= tv2.tv_sec -tv1.tv_sec;
dtv.tv_usec=tv2.tv_usec-tv1.tv_usec;
if(dtv.tv_usec<0) { dtv.tv_sec--; dtv.tv_usec+=1000000; }
return dtv.tv_sec*1000+dtv.tv_usec/1000;
}
int main()
{
time_start();
for(int t=0; t<1000000; t++)
printf("Test 1: %d\n", t);
printf("Result: %ld\n", time_stop());
}
I compile it and see this error:
test.c:5:17: error: storage size of ‘tz’ isn’t known
struct timezone tz;
^