benchmark-native.c 613 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. Test performance of native C UUID generation
  3. To Compile: cc -luuid benchmark-native.c -o benchmark-native
  4. */
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <sys/time.h>
  8. #include <uuid/uuid.h>
  9. int main() {
  10. uuid_t myid;
  11. char buf[36+1];
  12. int i;
  13. struct timeval t;
  14. double start, finish;
  15. gettimeofday(&t, NULL);
  16. start = t.tv_sec + t.tv_usec/1e6;
  17. int n = 2e5;
  18. for (i = 0; i < n; i++) {
  19. uuid_generate(myid);
  20. uuid_unparse(myid, buf);
  21. }
  22. gettimeofday(&t, NULL);
  23. finish = t.tv_sec + t.tv_usec/1e6;
  24. double dur = finish - start;
  25. printf("%d uuids/sec", (int)(n/dur));
  26. return 0;
  27. }