Project Euler Solutions
test_utils.h
Go to the documentation of this file.
1 #include <stdbool.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <time.h>
5 #include "../include/macros.h"
6 
7 #if (CL_COMPILER || defined(__MINGW32__) || defined(_WIN32) || defined(WIN32))
8  #include <windows.h> // for QueryPerformanceCounter()
9 #endif
10 
11 intmax_t nz_rand();
12 inline intmax_t nz_rand() {
13  intmax_t ret = rand();
14  while (!ret)
15  ret = rand();
16  return ret;
17 }
18 
19 unsigned long long perf_time();
20 inline unsigned long long perf_time() {
21  #if (CL_COMPILER || defined(__MINGW32__) || defined(_WIN32) || defined(WIN32))
22  LARGE_INTEGER t;
23  QueryPerformanceCounter(&t); // returns microseconds
24  return t.QuadPart * 1000;
25  #else
26  struct timespec t;
27  #if defined(CLOCK_PROCESS_CPUTIME_ID)
28  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
29  #elif defined(CLOCK_MONOTONIC)
30  clock_gettime(CLOCK_MONOTONIC, &t);
31  #else
32  clock_gettime(CLOCK_REALTIME, &t);
33  #endif
34  return t.tv_nsec + t.tv_sec * 1000000000;
35  #endif
36 }
unsigned long long perf_time()
Definition: test_utils.h:20
intmax_t nz_rand()
Definition: test_utils.h:12