summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c
blob: dbfc75f6d71778edde68642ac660ee3ec35a0ac9 (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
32
33
34
/*
Test performance of native C UUID generation

To Compile: cc -luuid benchmark-native.c -o benchmark-native
*/

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <uuid/uuid.h>

int main() {
  uuid_t myid;
  char buf[36+1];
  int i;
  struct timeval t;
  double start, finish;

  gettimeofday(&t, NULL);
  start = t.tv_sec + t.tv_usec/1e6;

  int n = 2e5;
  for (i = 0; i < n; i++) {
    uuid_generate(myid);
    uuid_unparse(myid, buf);
  }

  gettimeofday(&t, NULL);
  finish = t.tv_sec + t.tv_usec/1e6;
  double dur = finish - start;

  printf("%d uuids/sec", (int)(n/dur));
  return 0;
}