1
0

Benchmark.h 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef BENCHMARKH
  2. #define BENCHMARKH
  3. #if defined(_WIN32)
  4. static uint64_t Benchmark()
  5. {
  6. return GetTickCount64();
  7. }
  8. #elif defined(__ANDROID__)
  9. #include <time.h>
  10. // Make sure to divide by 1000000 (1 million) to get results in Milliseconds, as they are returned in nanoseconds
  11. static uint64_t Benchmark()
  12. {
  13. struct timespec ts;
  14. uint64_t count;
  15. clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
  16. count=(uint64_t)ts.tv_sec*1000000000ULL + (uint64_t)ts.tv_nsec;
  17. return count;
  18. }
  19. #elif defined(__APPLE__)
  20. #include <mach/mach_time.h>
  21. static uint64_t Benchmark()
  22. {
  23. uint64_t absoluteTime;
  24. static mach_timebase_info_data_t timeBase = {0,0};
  25. absoluteTime = mach_absolute_time();
  26. if (0 == timeBase.denom)
  27. {
  28. kern_return_t err = mach_timebase_info(&timeBase);
  29. if (0 != err)
  30. return 0;
  31. }
  32. uint64_t nanoTime = absoluteTime * timeBase.numer / timeBase.denom;
  33. return nanoTime/(1000*1000);
  34. }
  35. #endif
  36. #endif