"Fossies" - the Fresh Open Source Software Archive

Member "xxHash-0.8.0/tests/bench/bhDisplay.c" (27 Jul 2020, 5849 Bytes) of package /linux/misc/xxHash-0.8.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "bhDisplay.c": 0.7.3_vs_0.7.4.

    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 
   27 
   28 /* ===  Dependencies  === */
   29 
   30 #include <stdlib.h>   /* rand */
   31 #include <stdio.h>    /* printf */
   32 #include <assert.h>
   33 
   34 #include "benchHash.h"
   35 #include "bhDisplay.h"
   36 
   37 
   38 /* ===  benchmark large input  === */
   39 
   40 #define MB_UNIT           1000000
   41 #define BENCH_LARGE_ITER_MS   490
   42 #define BENCH_LARGE_TOTAL_MS 1010
   43 static void bench_oneHash_largeInput(Bench_Entry hashDesc, int minlog, int maxlog)
   44 {
   45     printf("%-7s", hashDesc.name);
   46     for (int sizelog=minlog; sizelog<=maxlog; sizelog++) {
   47         size_t const inputSize = (size_t)1 << sizelog;
   48         double const nbhps = bench_hash(hashDesc.hash, BMK_throughput,
   49                                         inputSize, BMK_fixedSize,
   50                                         BENCH_LARGE_TOTAL_MS, BENCH_LARGE_ITER_MS);
   51         printf(",%6.0f", nbhps * inputSize / MB_UNIT); fflush(NULL);
   52     }
   53     printf("\n");
   54 }
   55 
   56 void bench_largeInput(Bench_Entry const* hashDescTable, int nbHashes, int minlog, int maxlog)
   57 {
   58     assert(maxlog <  31);
   59     assert(minlog >=  0);
   60     printf("benchmarking large inputs : from %u bytes (log%i) to %u MB (log%i) \n",
   61         1U << minlog, minlog,
   62         (1U << maxlog) >> 20, maxlog);
   63     for (int i=0; i<nbHashes; i++)
   64         bench_oneHash_largeInput(hashDescTable[i], minlog, maxlog);
   65 }
   66 
   67 
   68 
   69 /* ===  Benchmark small inputs  === */
   70 
   71 #define BENCH_SMALL_ITER_MS   170
   72 #define BENCH_SMALL_TOTAL_MS  490
   73 static void bench_throughput_oneHash_smallInputs(Bench_Entry hashDesc, size_t sizeMin, size_t sizeMax)
   74 {
   75     printf("%-7s", hashDesc.name);
   76     for (size_t s=sizeMin; s<sizeMax+1; s++) {
   77         double const nbhps = bench_hash(hashDesc.hash, BMK_throughput,
   78                                         s, BMK_fixedSize,
   79                                         BENCH_SMALL_TOTAL_MS, BENCH_SMALL_ITER_MS);
   80         printf(",%10.0f", nbhps); fflush(NULL);
   81     }
   82     printf("\n");
   83 }
   84 
   85 void bench_throughput_smallInputs(Bench_Entry const* hashDescTable, int nbHashes, size_t sizeMin, size_t sizeMax)
   86 {
   87     printf("Throughput small inputs of fixed size : \n");
   88     for (int i=0; i<nbHashes; i++)
   89         bench_throughput_oneHash_smallInputs(hashDescTable[i], sizeMin, sizeMax);
   90 }
   91 
   92 
   93 
   94 /* ===   Latency measurements (small keys)   === */
   95 
   96 static void bench_latency_oneHash_smallInputs(Bench_Entry hashDesc, size_t size_min, size_t size_max)
   97 {
   98     printf("%-7s", hashDesc.name);
   99     for (size_t s=size_min; s<size_max+1; s++) {
  100         double const nbhps = bench_hash(hashDesc.hash, BMK_latency,
  101                                         s, BMK_fixedSize,
  102                                         BENCH_SMALL_TOTAL_MS, BENCH_SMALL_ITER_MS);
  103         printf(",%10.0f", nbhps); fflush(NULL);
  104     }
  105     printf("\n");
  106 }
  107 
  108 void bench_latency_smallInputs(Bench_Entry const* hashDescTable, int nbHashes, size_t size_min, size_t size_max)
  109 {
  110     printf("Latency for small inputs of fixed size : \n");
  111     for (int i=0; i<nbHashes; i++)
  112         bench_latency_oneHash_smallInputs(hashDescTable[i], size_min, size_max);
  113 }
  114 
  115 
  116 /* ===   Random input Length   === */
  117 
  118 static void bench_randomInputLength_withOneHash(Bench_Entry hashDesc, size_t size_min, size_t size_max)
  119 {
  120     printf("%-7s", hashDesc.name);
  121     for (size_t s=size_min; s<size_max+1; s++) {
  122         srand((unsigned)s);   /* ensure random sequence of length will be the same for a given s */
  123         double const nbhps = bench_hash(hashDesc.hash, BMK_throughput,
  124                                         s, BMK_randomSize,
  125                                         BENCH_SMALL_TOTAL_MS, BENCH_SMALL_ITER_MS);
  126         printf(",%10.0f", nbhps); fflush(NULL);
  127     }
  128     printf("\n");
  129 }
  130 
  131 void bench_throughput_randomInputLength(Bench_Entry const* hashDescTable, int nbHashes, size_t size_min, size_t size_max)
  132 {
  133     printf("benchmarking random size inputs [1-N] : \n");
  134     for (int i=0; i<nbHashes; i++)
  135         bench_randomInputLength_withOneHash(hashDescTable[i], size_min, size_max);
  136 }
  137 
  138 
  139 /* ===   Latency with Random input Length   === */
  140 
  141 static void bench_latency_oneHash_randomInputLength(Bench_Entry hashDesc, size_t size_min, size_t size_max)
  142 {
  143     printf("%-7s", hashDesc.name);
  144     for (size_t s=size_min; s<size_max+1; s++) {
  145         srand((unsigned)s);   /* ensure random sequence of length will be the same for a given s */
  146         double const nbhps = bench_hash(hashDesc.hash, BMK_latency,
  147                                         s, BMK_randomSize,
  148                                         BENCH_SMALL_TOTAL_MS, BENCH_SMALL_ITER_MS);
  149         printf(",%10.0f", nbhps); fflush(NULL);
  150     }
  151     printf("\n");
  152 }
  153 
  154 void bench_latency_randomInputLength(Bench_Entry const* hashDescTable, int nbHashes, size_t size_min, size_t size_max)
  155 {
  156     printf("Latency for small inputs of random size [1-N] : \n");
  157     for (int i=0; i<nbHashes; i++)
  158         bench_latency_oneHash_randomInputLength(hashDescTable[i], size_min, size_max);
  159 }