spir_test.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <sys/time.h>
  4. #include "spir.hpp"
  5. using std::cout;
  6. using std::cerr;
  7. static inline size_t elapsed_us(const struct timeval *start)
  8. {
  9. struct timeval end;
  10. gettimeofday(&end, NULL);
  11. return (end.tv_sec-start->tv_sec)*1000000 + end.tv_usec - start->tv_usec;
  12. }
  13. int main(int argc, char **argv)
  14. {
  15. if (argc < 2 || argc > 4) {
  16. cerr << "Usage: " << argv[0] << " r [num_threads [num_pirs]]\n";
  17. cerr << "r = log_2(num_records)\n";
  18. exit(1);
  19. }
  20. uint32_t r, num_threads = 1, num_pirs = 1;
  21. r = strtoul(argv[1], NULL, 10);
  22. if (argc > 2) {
  23. num_threads = strtoul(argv[2], NULL, 10);
  24. }
  25. if (argc > 3) {
  26. num_pirs = strtoul(argv[3], NULL, 10);
  27. }
  28. cout << "===== ONE-TIME SETUP =====\n\n";
  29. struct timeval otsetup_start;
  30. gettimeofday(&otsetup_start, NULL);
  31. SPIR::init(num_threads);
  32. string pub_params;
  33. SPIR_Client client(r, pub_params);
  34. printf("%u %u %u %u\n", (unsigned char)pub_params[0], (unsigned
  35. char)pub_params[1], (unsigned char)pub_params[2],
  36. (unsigned char)pub_params[3]);
  37. size_t otsetup_us = elapsed_us(&otsetup_start);
  38. cout << "OT one-time setup: " << otsetup_us << " µs\n";
  39. return 0;
  40. }