gettimeofday.c 519 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * Copyright 2015, Anton Blanchard, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #include <sys/time.h>
  6. #include <stdio.h>
  7. #include "utils.h"
  8. static int test_gettimeofday(void)
  9. {
  10. int i;
  11. struct timeval tv_start, tv_end;
  12. gettimeofday(&tv_start, NULL);
  13. for(i = 0; i < 100000000; i++) {
  14. gettimeofday(&tv_end, NULL);
  15. }
  16. printf("time = %.6f\n", tv_end.tv_sec - tv_start.tv_sec + (tv_end.tv_usec - tv_start.tv_usec) * 1e-6);
  17. return 0;
  18. }
  19. int main(void)
  20. {
  21. return test_harness(test_gettimeofday, "gettimeofday");
  22. }