jehanne/qa/lib/newlib/040-gettimeofday.c

23 lines
501 B
C
Raw Normal View History

2017-08-25 00:53:10 +02:00
#include <stdio.h>
#include <sys/time.h>
2017-08-28 02:47:05 +02:00
#include <unistd.h>
2017-08-25 00:53:10 +02:00
int main (int argc, char** argv) {
struct timeval tvalBefore, tvalAfter;
long delta;
gettimeofday (&tvalBefore, NULL);
2017-08-28 02:47:05 +02:00
sleep(2);
2017-08-25 00:53:10 +02:00
gettimeofday (&tvalAfter, NULL);
// Changed format to long int (%ld), changed time calculation
2017-08-25 23:33:10 +02:00
delta = (tvalAfter.tv_sec - tvalBefore.tv_sec)*1000000L
+(tvalAfter.tv_usec - tvalBefore.tv_usec);
2017-08-25 00:53:10 +02:00
printf("Time in microseconds: %ld microseconds\n", delta);
if(delta > 0)
return 0;
return 1;
}