ddlog_bench.c 812 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <assert.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <strings.h>
  5. #include "ddlog.h"
  6. #include "entropy.h"
  7. #include "group.h"
  8. #include "timeit.h"
  9. int main()
  10. {
  11. group_init();
  12. dlog_precompute();
  13. mpz_entropy_init();
  14. INIT_TIMEIT(CLOCK_PROCESS_CPUTIME_ID);
  15. uint32_t converted;
  16. for (int i=0; i < (int) (1e9 / (0x01 << strip_size) * 3.5); i++) {
  17. mpz_t n, n0;
  18. mpz_inits(n, n0, NULL);
  19. mpz_urandomm(n0, _rstate, p);
  20. mpz_set(n, n0);
  21. START_TIMEIT();
  22. converted = convert(n->_mp_d);
  23. END_TIMEIT();
  24. mpz_set(n, n0);
  25. #ifndef NDEBUG
  26. uint32_t expected = naif_convert(n);
  27. printf("%d %d\n", converted, expected);
  28. assert(converted == expected);
  29. #endif
  30. mpz_clears(n, n0, NULL);
  31. }
  32. printf(TIMEIT_FORMAT "\n", GET_TIMEIT());
  33. group_clear();
  34. return 0;
  35. }