summaryrefslogtreecommitdiff
path: root/numpy/random/src/mt19937/mt19937-benchmark.c
blob: 039f8030af65cc9dea77ea60a796ce8d956b6856 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * cl mt19937-benchmark.c mt19937.c /Ox
 * Measure-Command { .\mt19937-benchmark.exe }
 *
 * gcc mt19937-benchmark.c mt19937.c -O3 -o mt19937-benchmark
 * time ./mt19937-benchmark
 */
#include "mt19937.h"
#include <inttypes.h>
#include <stdio.h>
#include <time.h>

#define Q 1000000000

int main() {
  int i;
  uint32_t seed = 0x0;
  uint64_t sum = 0, count = 0;
  mt19937_state state;
  mt19937_seed(&state, seed);
  clock_t begin = clock();
  for (i = 0; i < Q; i++) {
    sum += mt19937_next64(&state);
    count++;
  }
  clock_t end = clock();
  double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("0x%" PRIx64 "\ncount: %" PRIu64 "\n", sum, count);
  printf("%" PRIu64 " randoms per second\n",
         (uint64_t)(Q / time_spent) / 1000000 * 1000000);
}