bhDisplay.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * CSV Display module for the hash benchmark program
  3. * Part of the xxHash project
  4. * Copyright (C) 2019-2020 Yann Collet
  5. *
  6. * GPL v2 License
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * You can contact the author at :
  23. * - xxHash homepage : https://www.xxhash.com
  24. * - xxHash source repository : https://github.com/Cyan4973/xxHash
  25. */
  26. /* === Dependencies === */
  27. #include <stdlib.h> /* rand */
  28. #include <stdio.h> /* printf */
  29. #include <assert.h>
  30. #include "benchHash.h"
  31. #include "bhDisplay.h"
  32. /* === benchmark large input === */
  33. #define MB_UNIT 1000000
  34. #define BENCH_LARGE_ITER_MS 490
  35. #define BENCH_LARGE_TOTAL_MS 1010
  36. static void bench_oneHash_largeInput(Bench_Entry hashDesc, int minlog, int maxlog)
  37. {
  38. printf("%-7s", hashDesc.name);
  39. for (int sizelog=minlog; sizelog<=maxlog; sizelog++) {
  40. size_t const inputSize = (size_t)1 << sizelog;
  41. double const nbhps = bench_hash(hashDesc.hash, BMK_throughput,
  42. inputSize, BMK_fixedSize,
  43. BENCH_LARGE_TOTAL_MS, BENCH_LARGE_ITER_MS);
  44. printf(",%6.0f", nbhps * inputSize / MB_UNIT); fflush(NULL);
  45. }
  46. printf("\n");
  47. }
  48. void bench_largeInput(Bench_Entry const* hashDescTable, int nbHashes, int minlog, int maxlog)
  49. {
  50. assert(maxlog < 31);
  51. assert(minlog >= 0);
  52. printf("benchmarking large inputs : from %u bytes (log%i) to %u MB (log%i) \n",
  53. 1U << minlog, minlog,
  54. (1U << maxlog) >> 20, maxlog);
  55. for (int i=0; i<nbHashes; i++)
  56. bench_oneHash_largeInput(hashDescTable[i], minlog, maxlog);
  57. }
  58. /* === Benchmark small inputs === */
  59. #define BENCH_SMALL_ITER_MS 170
  60. #define BENCH_SMALL_TOTAL_MS 490
  61. static void bench_throughput_oneHash_smallInputs(Bench_Entry hashDesc, size_t sizeMin, size_t sizeMax)
  62. {
  63. printf("%-7s", hashDesc.name);
  64. for (size_t s=sizeMin; s<sizeMax+1; s++) {
  65. double const nbhps = bench_hash(hashDesc.hash, BMK_throughput,
  66. s, BMK_fixedSize,
  67. BENCH_SMALL_TOTAL_MS, BENCH_SMALL_ITER_MS);
  68. printf(",%10.0f", nbhps); fflush(NULL);
  69. }
  70. printf("\n");
  71. }
  72. void bench_throughput_smallInputs(Bench_Entry const* hashDescTable, int nbHashes, size_t sizeMin, size_t sizeMax)
  73. {
  74. printf("Throughput small inputs of fixed size (from %zu to %zu bytes): \n",
  75. sizeMin, sizeMax);
  76. for (int i=0; i<nbHashes; i++)
  77. bench_throughput_oneHash_smallInputs(hashDescTable[i], sizeMin, sizeMax);
  78. }
  79. /* === Latency measurements (small keys) === */
  80. static void bench_latency_oneHash_smallInputs(Bench_Entry hashDesc, size_t size_min, size_t size_max)
  81. {
  82. printf("%-7s", hashDesc.name);
  83. for (size_t s=size_min; s<size_max+1; s++) {
  84. double const nbhps = bench_hash(hashDesc.hash, BMK_latency,
  85. s, BMK_fixedSize,
  86. BENCH_SMALL_TOTAL_MS, BENCH_SMALL_ITER_MS);
  87. printf(",%10.0f", nbhps); fflush(NULL);
  88. }
  89. printf("\n");
  90. }
  91. void bench_latency_smallInputs(Bench_Entry const* hashDescTable, int nbHashes, size_t size_min, size_t size_max)
  92. {
  93. printf("Latency for small inputs of fixed size : \n");
  94. for (int i=0; i<nbHashes; i++)
  95. bench_latency_oneHash_smallInputs(hashDescTable[i], size_min, size_max);
  96. }
  97. /* === Random input Length === */
  98. static void bench_randomInputLength_withOneHash(Bench_Entry hashDesc, size_t size_min, size_t size_max)
  99. {
  100. printf("%-7s", hashDesc.name);
  101. for (size_t s=size_min; s<size_max+1; s++) {
  102. srand((unsigned)s); /* ensure random sequence of length will be the same for a given s */
  103. double const nbhps = bench_hash(hashDesc.hash, BMK_throughput,
  104. s, BMK_randomSize,
  105. BENCH_SMALL_TOTAL_MS, BENCH_SMALL_ITER_MS);
  106. printf(",%10.0f", nbhps); fflush(NULL);
  107. }
  108. printf("\n");
  109. }
  110. void bench_throughput_randomInputLength(Bench_Entry const* hashDescTable, int nbHashes, size_t size_min, size_t size_max)
  111. {
  112. printf("benchmarking random size inputs [1-N] : \n");
  113. for (int i=0; i<nbHashes; i++)
  114. bench_randomInputLength_withOneHash(hashDescTable[i], size_min, size_max);
  115. }
  116. /* === Latency with Random input Length === */
  117. static void bench_latency_oneHash_randomInputLength(Bench_Entry hashDesc, size_t size_min, size_t size_max)
  118. {
  119. printf("%-7s", hashDesc.name);
  120. for (size_t s=size_min; s<size_max+1; s++) {
  121. srand((unsigned)s); /* ensure random sequence of length will be the same for a given s */
  122. double const nbhps = bench_hash(hashDesc.hash, BMK_latency,
  123. s, BMK_randomSize,
  124. BENCH_SMALL_TOTAL_MS, BENCH_SMALL_ITER_MS);
  125. printf(",%10.0f", nbhps); fflush(NULL);
  126. }
  127. printf("\n");
  128. }
  129. void bench_latency_randomInputLength(Bench_Entry const* hashDescTable, int nbHashes, size_t size_min, size_t size_max)
  130. {
  131. printf("Latency for small inputs of random size [1-N] : \n");
  132. for (int i=0; i<nbHashes; i++)
  133. bench_latency_oneHash_randomInputLength(hashDescTable[i], size_min, size_max);
  134. }