libposix: implement gettimeofday
This commit is contained in:
24
qa/lib/newlib/040-gettimeofday.c
Normal file
24
qa/lib/newlib/040-gettimeofday.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int main (int argc, char** argv) {
|
||||
struct timeval tvalBefore, tvalAfter;
|
||||
long delta;
|
||||
|
||||
gettimeofday (&tvalBefore, NULL);
|
||||
int i =0;
|
||||
while (i < 10000)
|
||||
i++;
|
||||
|
||||
gettimeofday (&tvalAfter, NULL);
|
||||
|
||||
// Changed format to long int (%ld), changed time calculation
|
||||
|
||||
delta = ((tvalAfter.tv_sec - tvalBefore.tv_sec)*1000000L
|
||||
+tvalAfter.tv_usec) - tvalBefore.tv_usec;
|
||||
printf("Time in microseconds: %ld microseconds\n", delta);
|
||||
|
||||
if(delta > 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
Reference in New Issue
Block a user