Skip to content

Commit

Permalink
Add weighted average to SpeedSmall test output
Browse files Browse the repository at this point in the history
It addresses the question at #113

What is the "real" average cycles/hash value for a given hash function?

We can't know, but we can estimate it better if we assume that the
function timing does not depend on input (that's not true for hashes
based on multiplication) and we know distribution of key length in
advance (that might be somewhat known for certain classes of inputs,
but the distribution varies across classes measurably).
  • Loading branch information
darkk committed Aug 30, 2024
1 parent 0c6a1ef commit c75df73
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 12 deletions.
16 changes: 13 additions & 3 deletions Platform.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#include "Platform.h"

#include <stdio.h>
#include <assert.h>

void testRDTSC ( void )
long getenvlong(const char *name, long minval, long defval, long maxval)
{
int64_t temp = rdtsc();
printf("%ld",(long)temp);
assert(minval <= defval && defval <= maxval);
const char *s = getenv(name);
if (!s)
return defval;
char *tail;
long l = strtol(s, &tail, 0);
if (*tail)
return defval;
if (l < minval) l = minval;
if (l > maxval) l = maxval;
return l;
}

#if defined(_WIN32)
Expand Down
1 change: 1 addition & 0 deletions Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void SetThreadAffinity ( std::thread &t, int cpu );
# endif
#endif
void SetAffinity ( int cpu );
long getenvlong(const char *name, long minval, long defval, long maxval);

// That's not UINT64_MAX as it's converted to int64_t sometimes.
constexpr uint64_t timer_inf = INT64_MAX;
Expand Down
2 changes: 1 addition & 1 deletion SpeedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ double SpeedTest ( pfHash hash, uint32_t seed, const int trials, const int block

double t;

if(blocksize < 100)
if(blocksize <= TIMEHASH_SMALL_LEN_MAX)
{
t = (double)timehash_small(hash,block,blocksize,itrial);
}
Expand Down
2 changes: 2 additions & 0 deletions SpeedTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Types.h"

constexpr int TIMEHASH_SMALL_LEN_MAX = 255;

void BulkSpeedTest ( pfHash hash, uint32_t seed );
double TinySpeedTest ( pfHash hash, int hashsize, int keysize, uint32_t seed, bool verbose );
double HashMapSpeedTest ( pfHash pfhash, int hashbits, std::vector<std::string> words,
Expand Down
199 changes: 191 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ bool MomentChi2Test ( struct HashInfo *info, int inputSize );
//-----------------------------------------------------------------------------
// This is the list of all hashes that SMHasher can test.

#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))

const char* quality_str[3] = { "SKIP", "POOR", "GOOD" };

// sorted by quality and speed. the last is the list of internal secrets to be tested against bad seeds.
Expand Down Expand Up @@ -979,6 +981,162 @@ void SelfTest(bool verbose) {

//----------------------------------------------------------------------------

// These probability tables for weighted average exist under assumption that hash speed does not depend
// on input, which is not 100% true due to multiplication instruction having certain amount of variance.

// Probability of a DNS name length without trailing dot from a real-world 1 GiB pcap having 3408617
// eyeballs requests of the following types: A (2238713), AAAA (567276), SVCB (10699), HTTPS (571003),
// TXT (14376), SRV (6550).
//
// $ lz4cat dnsdump.pcap.lz4 | tcpdump -n -r - 'udp dst port 53' |
// awk 'BEGIN { for (i=0; i<256; i++) a[i] = 0; }
// ($7 == "A?" || $7 == "AAAA?" || $7 == "TXT?" || $7 == "SRV?" || $7 == "Type64?" || $7 == "Type65?")
// { l = length($8) - 1; a[l]++; }
// END { s = 0; for (l in a) { s += a[l] }; for (l in a) print l, a[l] / s; print "Total", s }'
//
const double DNSQueryLenProbability[256] = {0.000243794, 4.42995e-05, 1.67223e-05, 8.30249e-05,
0.000413071, 0.00852927, 0.00435954, 0.00318516, 0.00280642, 0.0195766, 0.0231094, 0.0258213,
0.0498657, 0.0402694, 0.0526087, 0.0701299, 0.0590958, 0.0434015, 0.0785814, 0.0729865, 0.043941,
0.0374477, 0.0455833, 0.0285931, 0.0261745, 0.0281117, 0.0332918, 0.0276215, 0.0224909, 0.0240441,
0.0117716, 0.024791, 0.0159995, 0.0118362, 0.0117405, 0.0125288, 0.00655838, 0.00388574,
0.00271459, 0.00356978, 0.00299682, 0.00361877, 0.00205069, 0.00168602, 0.00214633, 0.00091386,
0.000634862, 0.000826142, 0.000637795, 0.00229624, 0.00038696, 0.00031391, 0.000226778,
0.000171624, 0.000204482, 0.000237926, 0.000131432, 0.000210349, 0.000111776, 6.04351e-05,
6.07284e-05, 0.000186879, 0.000377572, 7.48104e-05, 8.97725e-05, 1.67223e-05, 3.57916e-05,
2.08296e-05, 7.30502e-05, 1.87759e-05, 0.00084169, 9.7987e-05, 1.29085e-05, 2.55235e-05,
9.38797e-06, 1.34952e-05, 9.38797e-06, 1.93627e-05, 5.92616e-05, 9.68135e-06, 1.99494e-05,
2.22964e-05, 4.01923e-05, 1.20283e-05, 1.1735e-06, 0, 1.1735e-06, 1.1735e-06, 0, 2.93374e-07,
2.64037e-06, 2.05362e-06, 5.86748e-07, 2.93374e-07, 2.93374e-07, 1.76024e-06, 0, 1.46687e-06,
2.93374e-07, 5.86748e-07, 0, 0, 0, 0, 1.46687e-06, 0, 0, 0, 0, 0, 0.000132605, 0, 2.93374e-07,
0, 0, 2.93374e-07, 0, 0, 0, 2.93374e-07, 0, 0, 0, 5.86748e-07, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 8.80122e-07, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2.93374e-07, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.93374e-07, 0, 0, 2.93374e-07, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2.93374e-07,
0, 0, 0, 0, 5.86748e-07, 0, 2.93374e-07, 7.33435e-06, 0, 0, 5.86748e-06, 0, 0};

// Probability of a DNS name length without trailing dot from a compilation of "top 1M domains"
// lists totalling 2655211 unique domains. That might be different from DNSQueryLen as user's
// query is not the same thing as mere existence of the name in some configuration file.
//
const double DNSTopNameLenProbability[256] = { 0, 0, 8.96351e-05, 8.13495e-05, 0.000174751, 0.0012805,
0.00732446, 0.0162925, 0.0273146, 0.0420867, 0.0661081, 0.0650724, 0.0677035, 0.068233, 0.0659963,
0.0624979, 0.0589177, 0.0524911, 0.0460276, 0.0398857, 0.035584, 0.0321281, 0.0255324, 0.0210224,
0.018655, 0.0164119, 0.0143925, 0.0134332, 0.0115317, 0.0105705, 0.00989413, 0.00900117,
0.00934577, 0.00761936, 0.00649139, 0.00518302, 0.00510016, 0.0050576, 0.00426369, 0.0062093,
0.00333269, 0.0028687, 0.00341253, 0.00239755, 0.00270901, 0.00212149, 0.00214145, 0.00189401,
0.00165712, 0.00195088, 0.00122213, 0.00170872, 0.00156409, 0.0010485, 0.00186652, 0.00133586,
0.000825546, 0.000708795, 0.000692977, 0.000509564, 0.000440266, 0.000958493, 0.000482824,
0.000674523, 0.000467759, 0.0002561, 0.000245931, 0.000299788, 0.000300164, 0.000248568,
0.000259113, 0.000293385, 0.000116752, 0.000159686, 0.000109972, 7.83365e-05, 0.000136336,
0.000122777, 6.2142e-05, 5.4233e-05, 0.000432357, 5.34797e-05, 0.000109219, 9.98037e-05,
4.1428e-05, 4.33111e-05, 3.65319e-05, 4.29344e-05, 2.89996e-05, 2.78697e-05, 3.99215e-05,
4.1428e-05, 1.80777e-05, 5.95056e-05, 2.89996e-05, 3.42722e-05, 3.20125e-05, 5.15967e-05,
0.000418046, 2.93762e-05, 4.10514e-05, 2.97528e-05, 1.88309e-05, 2.0714e-05, 1.7701e-05,
2.14672e-05, 1.80777e-05, 2.59866e-05, 2.10906e-05, 2.44802e-05, 0.000169101, 1.7701e-05,
1.43115e-05, 1.2805e-05, 1.01687e-05, 9.41545e-06, 7.90898e-06, 9.03883e-06, 1.05453e-05,
1.09219e-05, 9.41545e-06, 9.79207e-06, 7.90898e-06, 1.39349e-05, 1.09219e-05, 9.79207e-06,
9.79207e-06, 1.09219e-05, 1.05453e-05, 1.2805e-05, 6.02589e-06, 1.46881e-05, 1.12985e-05,
1.5818e-05, 2.03374e-05, 1.54413e-05, 2.63633e-05, 2.33503e-05, 1.65712e-05, 1.7701e-05,
2.44802e-05, 1.39349e-05, 1.39349e-05, 2.18438e-05, 2.52334e-05, 1.88309e-05, 1.65712e-05,
2.29737e-05, 2.44802e-05, 1.31816e-05, 1.84543e-05, 1.80777e-05, 9.79207e-06, 1.12985e-05,
1.12985e-05, 8.28559e-06, 6.4025e-06, 6.77912e-06, 6.4025e-06, 5.64927e-06, 4.51941e-06,
6.77912e-06, 4.1428e-06, 6.02589e-06, 5.27265e-06, 7.15574e-06, 6.77912e-06, 6.02589e-06,
3.76618e-06, 6.4025e-06, 3.01294e-06, 5.27265e-06, 3.76618e-06, 4.51941e-06, 3.76618e-06,
6.77912e-06, 3.38956e-06, 6.02589e-06, 4.89603e-06, 5.27265e-06, 6.02589e-06, 5.27265e-06,
5.27265e-06, 7.90898e-06, 4.89603e-06, 1.09219e-05, 4.89603e-06, 9.41545e-06, 7.15574e-06,
8.66221e-06, 4.89603e-06, 8.28559e-06, 7.53236e-06, 8.28559e-06, 4.51941e-06, 1.05453e-05,
6.4025e-06, 1.01687e-05, 6.4025e-06, 9.03883e-06, 6.02589e-06, 9.03883e-06, 5.64927e-06,
7.53236e-06, 3.01294e-06, 6.02589e-06, 3.38956e-06, 5.27265e-06, 5.27265e-06, 5.27265e-06,
3.38956e-06, 4.89603e-06, 3.01294e-06, 4.89603e-06, 3.01294e-06, 6.02589e-06, 3.38956e-06,
9.41545e-06, 3.38956e-06, 5.64927e-06, 1.50647e-06, 6.77912e-06, 1.88309e-06, 4.51941e-06,
1.88309e-06, 4.89603e-06, 3.38956e-06, 4.89603e-06, 2.63633e-06, 9.41545e-06, 3.01294e-06,
4.51941e-06, 5.27265e-06, 6.02589e-06, 3.76618e-06, 4.89603e-06, 1.88309e-06, 4.89603e-06,
1.88309e-06, 4.89603e-06, 2.63633e-06, 5.64927e-06, 3.76618e-06, 5.64927e-06, 7.53236e-06,
7.15574e-06, 2.25971e-06, 4.89603e-06, 2.63633e-06, 2.63633e-06, 3.76618e-07, 2.25971e-06,
0, 2.41035e-05, 0, 0};

// That's like top-1m above, but it's a compilation of 11,640,340 domains coming from varous
// blocklists and zone dumps. It it relevant? No. But it's 200 MiB of domain names :-)
//
const double DNSTailNameLenProbability[256] = { 0, 0, 2.04461e-05, 1.88139e-05, 4.38991e-05,
0.000415452, 0.00569829, 0.0195254, 0.0315039, 0.0517829, 0.0780355, 0.0819671, 0.0884572,
0.0811914, 0.0755655, 0.0658041, 0.0581139, 0.0488786, 0.0419683, 0.0357179, 0.0302831, 0.024542,
0.0216147, 0.0177761, 0.0156073, 0.0128184, 0.0108588, 0.0111896, 0.00917052, 0.00945325,
0.00958932, 0.00751825, 0.0058762, 0.00448535, 0.00375255, 0.00332044, 0.00331898, 0.00344157,
0.00232004, 0.00294519, 0.00238395, 0.00197804, 0.00168139, 0.00206695, 0.00134214, 0.00115512,
0.00108846, 0.000968786, 0.000897998, 0.000961656, 0.000778156, 0.0007913, 0.000670513,
0.000639242, 0.000693622, 0.00056665, 0.000409352, 0.000364251, 0.000445176, 0.000279631,
0.0002658, 0.00037224, 0.000240801, 0.00026013, 0.000214599, 0.000126199, 0.000117265,
0.000129549, 0.000132127, 0.000105581, 9.95675e-05, 0.000108674, 5.30053e-05, 9.50144e-05,
0.000114172, 4.16654e-05, 7.65442e-05, 4.66481e-05, 2.96383e-05, 2.76624e-05, 0.000113485,
2.02743e-05, 0.00057988, 0.000310042, 1.67521e-05, 1.57212e-05, 1.25426e-05, 1.3058e-05,
1.37453e-05, 1.05667e-05, 1.34876e-05, 1.31439e-05, 0.000549898, 0.000296039, 1.51198e-05,
1.09103e-05, 1.09103e-05, 1.62366e-05, 0.000101715, 8.67672e-06, 1.15976e-05, 9.62171e-06,
6.09948e-06, 6.52902e-06, 9.36399e-06, 6.01357e-06, 6.18539e-06, 9.36399e-06, 5.75585e-06,
6.52902e-06, 3.91741e-05, 5.3263e-06, 4.2095e-06, 6.78674e-06, 2.74906e-06, 3.26451e-06,
2.1477e-06, 3.1786e-06, 3.43633e-06, 5.15449e-06, 3.00679e-06, 3.1786e-06, 2.23361e-06,
4.12359e-06, 3.1786e-06, 3.09269e-06, 3.95177e-06, 3.52223e-06, 3.00679e-06, 3.43633e-06,
1.97589e-06, 4.03768e-06, 3.1786e-06, 4.63904e-06, 4.98267e-06, 4.12359e-06, 6.61493e-06,
5.92766e-06, 4.38132e-06, 4.89676e-06, 6.44311e-06, 4.46722e-06, 3.77996e-06, 5.41221e-06,
5.84175e-06, 4.89676e-06, 4.55313e-06, 5.84175e-06, 5.84175e-06, 3.60814e-06, 4.98267e-06,
4.63904e-06, 3.00679e-06, 3.00679e-06, 2.74906e-06, 2.23361e-06, 2.1477e-06, 2.31952e-06,
1.88998e-06, 1.71816e-06, 1.63225e-06, 2.31952e-06, 1.11681e-06, 1.71816e-06, 1.37453e-06,
1.97589e-06, 1.63225e-06, 1.97589e-06, 1.46044e-06, 2.0618e-06, 6.87265e-07, 1.63225e-06,
1.46044e-06, 1.46044e-06, 1.28862e-06, 2.1477e-06, 1.11681e-06, 1.80407e-06, 1.20271e-06,
1.63225e-06, 1.37453e-06, 1.63225e-06, 1.37453e-06, 2.31952e-06, 1.28862e-06, 3.09269e-06,
1.80407e-06, 2.74906e-06, 2.0618e-06, 2.40543e-06, 1.28862e-06, 2.1477e-06, 2.0618e-06,
2.23361e-06, 1.37453e-06, 2.83497e-06, 1.63225e-06, 2.49134e-06, 1.97589e-06, 2.31952e-06,
1.54635e-06, 2.31952e-06, 1.46044e-06, 1.88998e-06, 8.59081e-07, 1.46044e-06, 8.59081e-07,
1.63225e-06, 1.63225e-06, 1.28862e-06, 1.0309e-06, 1.28862e-06, 8.59081e-07, 1.37453e-06,
7.73173e-07, 1.54635e-06, 9.4499e-07, 2.23361e-06, 7.73173e-07, 1.46044e-06, 3.43633e-07,
1.80407e-06, 6.01357e-07, 1.28862e-06, 7.73173e-07, 1.37453e-06, 8.59081e-07, 1.28862e-06,
7.73173e-07, 2.31952e-06, 7.73173e-07, 1.11681e-06, 1.20271e-06, 1.63225e-06, 9.4499e-07,
1.20271e-06, 4.29541e-07, 1.20271e-06, 5.15449e-07, 1.37453e-06, 6.01357e-07, 1.37453e-06,
8.59081e-07, 1.37453e-06, 1.71816e-06, 1.80407e-06, 6.01357e-07, 1.37453e-06, 6.01357e-07,
6.87265e-07, 1.71816e-07, 6.01357e-07, 0, 5.92766e-06, 0, 0};

// This distribution comes from https://github.com/backtrace-labs/umash/wiki/Execution-traces
// startup-1M.2020-08-28.trace.bz2 file has 1,000,000 umash_full() samples of key lengths.
// Two other files have boring distribution for umash_full: startup-tail-1M.2020-08-28.trace.bz2
// has 99.9974% lines with "arg4=65" and steady-state.2020-08-28.trace.bz2 is not that less boring:
// len=4 for 5.5%, len=64 for 85.4%, and len=65 for 9.1% lines.
const double UMashStartHeadProbability[256] = { 0, 7e-06, 5.1e-05, 0.000396, 0.001312, 0.00311,
0.005616, 0.007887, 0.011145, 0.068172, 0.014618, 0.01667, 0.009502, 0.008275, 0.007444, 0.008088,
0.105451, 0.000246, 0.0001, 0.000117, 0.000116, 0.000487, 0.000367, 0.000179, 0.000293, 5.8e-05,
5.6e-05, 0.000124, 0.000191, 0.00034, 0.000323, 0.000333, 0.000303, 0.000274, 0.000238, 0.000202,
0.000246, 0.409961, 0.000235, 0.010119, 0.000239, 0.000171, 0.000128, 0.0001, 0.005217, 5.1e-05,
6.2e-05, 5.3e-05, 4.2e-05, 6.9e-05, 6.3e-05, 8.9e-05, 3.8e-05, 5.2e-05, 0.000102, 8.4e-05,
9e-05, 7.5e-05, 6.1e-05, 9e-05, 5.5e-05, 5.7e-05, 6e-05, 7.1e-05, 0.000106, 0.09252, 5.4e-05,
5.7e-05, 0.000101, 0.000316, 0.000961, 0.001873, 0.001714, 0.00029, 8.8e-05, 0.000185, 0.0006,
0.001038, 0.001762, 0.003228, 0.003174, 0.000284, 0.000266, 0.000292, 0.000752, 0.001381,
0.001331, 0.000145, 0.000161, 0.000177, 0.001517, 0.000304, 0.000176, 0.009464, 0.000342,
0.001809, 0.000286, 0.000962, 0.000116, 0.00039, 0.000383, 0.000244, 5e-05, 5.4e-05, 4.6e-05,
8.8e-05, 0.000191, 7.4e-05, 5.4e-05, 9.1e-05, 0.00011, 0.011347, 0.00431, 0.005021, 5.1e-05,
0.000189, 0.000902, 6e-05, 0.003476, 0.044543, 0.000275, 0.00596, 5.8e-05, 0.001705, 8.4e-05,
1.5e-05, 3.4e-05, 6.8e-05, 0.001113, 4.3e-05, 5.5e-05, 2.7e-05, 0.000126, 1.5e-05, 3.3e-05,
0.001512, 1.4e-05, 0.000359, 1.3e-05, 4.3e-05, 0.007604, 0.078108, 4.3e-05, 2.7e-05, 7e-06,
2.3e-05, 0.00014, 5e-06, 3e-06, 0, 1.3e-05, 6e-06, 8e-06, 3.3e-05, 5.4e-05, 3e-06, 0, 0,
1.3e-05, 1e-05, 1.3e-05, 0, 6e-06, 5e-06, 1.1e-05, 0, 1.1e-05, 2.5e-05, 1.1e-05, 9e-06, 0,
1.2e-05, 1.3e-05, 0, 0, 4.1e-05, 3e-06, 4e-06, 8e-06, 4.9e-05, 2.9e-05, 2.5e-05, 1.7e-05, 1e-05,
3e-06, 2.9e-05, 7e-06, 9e-06, 2e-06, 2e-05, 1.7e-05, 1.7e-05, 5e-06, 3.5e-05, 3e-06, 5e-06, 0,
1.3e-05, 0, 0.000149, 1.7e-05, 6e-06, 8e-06, 3e-06, 1.1e-05, 1.7e-05, 0, 1e-06, 0.00078, 0, 0,
1.4e-05, 2.9e-05, 1e-05, 3e-06, 1.4e-05, 2e-05, 9e-06, 1.2e-05, 2.9e-05, 1.1e-05, 6e-06, 1e-05,
6e-06, 1.2e-05, 0, 1e-05, 7e-06, 2.2e-05, 1.3e-05, 6e-06, 1e-05, 1.4e-05, 0.000167, 0, 3e-06,
0, 1.1e-05, 7e-06, 5e-06, 9e-06, 3.5e-05, 4e-06, 5e-06, 7e-06, 2e-06, 1.4e-05, 6e-06, 7e-06,
2e-06, 1.6e-05, 5e-06, 6e-06, 8e-06, 0, 4e-06};

static std::pair<double, double> CalcWAvg(const double *x, const double *dist, size_t imin, size_t imax)
{
double sum = 0, prb = 0;
for (size_t i = imin; i <= imax; i++) {
sum += dist[i] * x[i];
prb += dist[i];
}
sum /= prb;
return std::make_pair(sum, prb);
}

template < typename hashtype >
void test ( hashfunc<hashtype> hash, HashInfo* info )
{
Expand Down Expand Up @@ -1027,7 +1185,6 @@ void test ( hashfunc<hashtype> hash, HashInfo* info )

if(g_testSpeedBulk || g_testSpeedSmall || g_testAll)
{
double sum = 0.0;
printf("[[[ Speed Tests ]]]\n\n");
if (timer_counts_ns())
printf("WARNING: no cycle counter, cycle == 1ns\n");
Expand All @@ -1050,17 +1207,43 @@ void test ( hashfunc<hashtype> hash, HashInfo* info )
}

if (g_testSpeedSmall || g_testAll) {
const char* const envsmin = getenv("SMHASHER_SMALLKEY_MIN");
const char* const envsmax = getenv("SMHASHER_SMALLKEY_MAX");
const int minkey = max(min(envsmin ? atoi(envsmin) : 1, 255), 1);
const int maxkey = max(min(envsmax ? atoi(envsmax) : 32, 255), minkey);
const int dflmax = g_testExtra ? 64 : 32;
const int minkey = getenvlong("SMHASHER_SMALLKEY_MIN", 1, 1, TIMEHASH_SMALL_LEN_MAX);
const int maxkey = getenvlong("SMHASHER_SMALLKEY_MAX", minkey, dflmax, TIMEHASH_SMALL_LEN_MAX);
double cph[TIMEHASH_SMALL_LEN_MAX + 1];
for(int i = minkey; i <= maxkey; i++)
{
volatile int j = i;
sum += TinySpeedTest(hashfunc<hashtype>(info->hash),sizeof(hashtype),j,info->verification,true);
cph[j] = TinySpeedTest(hashfunc<hashtype>(info->hash),sizeof(hashtype),j,info->verification,true);
}
{
double sum = 0;
for (int i = minkey; i <= maxkey; i++)
sum += cph[i];
sum /= (maxkey - minkey + 1);
g_speed = sum;
printf("Average %8.3f cycles/hash\n",sum);
}
{
static_assert(COUNT_OF(cph) == COUNT_OF(DNSQueryLenProbability), "len(weights) != len(vector)");
const auto q = CalcWAvg(cph, DNSQueryLenProbability, minkey, maxkey);
printf("Average DNS query (|%5.1f%% of query.log) %8.3f cycles/hash\n",100.*q.second,q.first);
}
{
static_assert(COUNT_OF(cph) == COUNT_OF(DNSTopNameLenProbability), "len(weights) != len(vector)");
const auto m = CalcWAvg(cph, DNSTopNameLenProbability, minkey, maxkey);
printf("Average DNS name (|%5.1f%% of top-1m.csv) %8.3f cycles/hash\n",100.*m.second,m.first);
}
{
static_assert(COUNT_OF(cph) == COUNT_OF(DNSTailNameLenProbability), "len(weights) != len(vector)");
const auto d = CalcWAvg(cph, DNSTailNameLenProbability, minkey, maxkey);
printf("Average DNS name (|%5.1f%% of 200MiB.zone)%8.3f cycles/hash\n",100.*d.second,d.first);
}
{
static_assert(COUNT_OF(cph) == COUNT_OF(UMashStartHeadProbability), "len(weights) != len(vector)");
const auto u = CalcWAvg(cph, UMashStartHeadProbability, minkey, maxkey);
printf("Average UMASH (|%5.1f%% of startup-1M.bz2)%8.3f cycles/hash\n",100.*u.second,u.first);
}
g_speed = sum = sum / (maxkey - minkey + 1);
printf("Average %6.3f cycles/hash\n",sum);
printf("\n");
fflush(NULL);
}
Expand Down

0 comments on commit c75df73

Please sign in to comment.