perf_kdf.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2002, 2003, 2004, 2006, 2013 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. * @file nse/perf_kdf.c
  19. * @brief measure performance of KDF hash function
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include <gcrypt.h>
  24. #include <gauger.h>
  25. static void
  26. perfHash ()
  27. {
  28. struct GNUNET_HashCode hc;
  29. char buf[64];
  30. memset (buf, 1, sizeof(buf));
  31. for (unsigned int i = 0; i < 1024; i++)
  32. GNUNET_CRYPTO_pow_hash ("gnunet-nse-proof",
  33. buf,
  34. sizeof(buf),
  35. &hc);
  36. }
  37. int
  38. main (int argc, char *argv[])
  39. {
  40. struct GNUNET_TIME_Absolute start;
  41. start = GNUNET_TIME_absolute_get ();
  42. perfHash ();
  43. printf ("Hash perf took %s\n",
  44. GNUNET_STRINGS_relative_time_to_string (
  45. GNUNET_TIME_absolute_get_duration (start),
  46. GNUNET_YES));
  47. GAUGER ("NSE", "Proof-of-work hashing",
  48. 1024.0 / (1.0
  49. + GNUNET_TIME_absolute_get_duration
  50. (start).rel_value_us / 1000.0), "hashes/ms");
  51. return 0;
  52. }
  53. /* end of perf_kdf.c */