Skip to content

Commit 6522c51

Browse files
committed
Add weighted average to SpeedSmall test output
It addresses the question at rurban#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).
1 parent 0c6a1ef commit 6522c51

File tree

5 files changed

+208
-12
lines changed

5 files changed

+208
-12
lines changed

Platform.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
#include "Platform.h"
22

33
#include <stdio.h>
4+
#include <assert.h>
45

5-
void testRDTSC ( void )
6+
long getenvlong(const char *name, long minval, long defval, long maxval)
67
{
7-
int64_t temp = rdtsc();
8-
printf("%ld",(long)temp);
8+
assert(minval <= defval && defval <= maxval);
9+
const char *s = getenv(name);
10+
if (!s)
11+
return defval;
12+
char *tail;
13+
long l = strtol(s, &tail, 0);
14+
if (*tail)
15+
return defval;
16+
if (l < minval) l = minval;
17+
if (l > maxval) l = maxval;
18+
return l;
919
}
1020

1121
#if defined(_WIN32)

Platform.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void SetThreadAffinity ( std::thread &t, int cpu );
2121
# endif
2222
#endif
2323
void SetAffinity ( int cpu );
24+
long getenvlong(const char *name, long minval, long defval, long maxval);
2425

2526
// That's not UINT64_MAX as it's converted to int64_t sometimes.
2627
constexpr uint64_t timer_inf = INT64_MAX;

SpeedTest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ double SpeedTest ( pfHash hash, uint32_t seed, const int trials, const int block
240240

241241
double t;
242242

243-
if(blocksize < 100)
243+
if(blocksize <= TIMEHASH_SMALL_LEN_MAX)
244244
{
245245
t = (double)timehash_small(hash,block,blocksize,itrial);
246246
}

SpeedTest.h

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "Types.h"
44

5+
constexpr int TIMEHASH_SMALL_LEN_MAX = 255;
6+
57
void BulkSpeedTest ( pfHash hash, uint32_t seed );
68
double TinySpeedTest ( pfHash hash, int hashsize, int keysize, uint32_t seed, bool verbose );
79
double HashMapSpeedTest ( pfHash pfhash, int hashbits, std::vector<std::string> words,

main.cpp

+191-8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ bool MomentChi2Test ( struct HashInfo *info, int inputSize );
8686
//-----------------------------------------------------------------------------
8787
// This is the list of all hashes that SMHasher can test.
8888

89+
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
90+
8991
const char* quality_str[3] = { "SKIP", "POOR", "GOOD" };
9092

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

980982
//----------------------------------------------------------------------------
981983

984+
// These probability tables for weighted average exist under assumption that hash speed does not depend
985+
// on input, which is not 100% true due to multiplication instruction having certain amount of variance.
986+
987+
// Probability of a DNS name length without trailing dot from a real-world 1 GiB pcap having 3408617
988+
// eyeballs requests of the following types: A (2238713), AAAA (567276), SVCB (10699), HTTPS (571003),
989+
// TXT (14376), SRV (6550).
990+
//
991+
// $ lz4cat dnsdump.pcap.lz4 | tcpdump -n -r - 'udp dst port 53' |
992+
// awk 'BEGIN { for (i=0; i<256; i++) a[i] = 0; }
993+
// ($7 == "A?" || $7 == "AAAA?" || $7 == "TXT?" || $7 == "SRV?" || $7 == "Type64?" || $7 == "Type65?")
994+
// { l = length($8) - 1; a[l]++; }
995+
// END { s = 0; for (l in a) { s += a[l] }; for (l in a) print l, a[l] / s; print "Total", s }'
996+
//
997+
const double DNSQueryLenProbability[256] = {0.000243794, 4.42995e-05, 1.67223e-05, 8.30249e-05,
998+
0.000413071, 0.00852927, 0.00435954, 0.00318516, 0.00280642, 0.0195766, 0.0231094, 0.0258213,
999+
0.0498657, 0.0402694, 0.0526087, 0.0701299, 0.0590958, 0.0434015, 0.0785814, 0.0729865, 0.043941,
1000+
0.0374477, 0.0455833, 0.0285931, 0.0261745, 0.0281117, 0.0332918, 0.0276215, 0.0224909, 0.0240441,
1001+
0.0117716, 0.024791, 0.0159995, 0.0118362, 0.0117405, 0.0125288, 0.00655838, 0.00388574,
1002+
0.00271459, 0.00356978, 0.00299682, 0.00361877, 0.00205069, 0.00168602, 0.00214633, 0.00091386,
1003+
0.000634862, 0.000826142, 0.000637795, 0.00229624, 0.00038696, 0.00031391, 0.000226778,
1004+
0.000171624, 0.000204482, 0.000237926, 0.000131432, 0.000210349, 0.000111776, 6.04351e-05,
1005+
6.07284e-05, 0.000186879, 0.000377572, 7.48104e-05, 8.97725e-05, 1.67223e-05, 3.57916e-05,
1006+
2.08296e-05, 7.30502e-05, 1.87759e-05, 0.00084169, 9.7987e-05, 1.29085e-05, 2.55235e-05,
1007+
9.38797e-06, 1.34952e-05, 9.38797e-06, 1.93627e-05, 5.92616e-05, 9.68135e-06, 1.99494e-05,
1008+
2.22964e-05, 4.01923e-05, 1.20283e-05, 1.1735e-06, 0, 1.1735e-06, 1.1735e-06, 0, 2.93374e-07,
1009+
2.64037e-06, 2.05362e-06, 5.86748e-07, 2.93374e-07, 2.93374e-07, 1.76024e-06, 0, 1.46687e-06,
1010+
2.93374e-07, 5.86748e-07, 0, 0, 0, 0, 1.46687e-06, 0, 0, 0, 0, 0, 0.000132605, 0, 2.93374e-07,
1011+
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,
1012+
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,
1013+
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,
1014+
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,
1015+
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,
1016+
0, 0, 0, 0, 5.86748e-07, 0, 2.93374e-07, 7.33435e-06, 0, 0, 5.86748e-06, 0, 0};
1017+
1018+
// Probability of a DNS name length without trailing dot from a compilation of "top 1M domains"
1019+
// lists totalling 2655211 unique domains. That might be different from DNSQueryLen as user's
1020+
// query is not the same thing as mere existence of the name in some configuration file.
1021+
//
1022+
const double DNSTopNameLenProbability[256] = { 0, 0, 8.96351e-05, 8.13495e-05, 0.000174751, 0.0012805,
1023+
0.00732446, 0.0162925, 0.0273146, 0.0420867, 0.0661081, 0.0650724, 0.0677035, 0.068233, 0.0659963,
1024+
0.0624979, 0.0589177, 0.0524911, 0.0460276, 0.0398857, 0.035584, 0.0321281, 0.0255324, 0.0210224,
1025+
0.018655, 0.0164119, 0.0143925, 0.0134332, 0.0115317, 0.0105705, 0.00989413, 0.00900117,
1026+
0.00934577, 0.00761936, 0.00649139, 0.00518302, 0.00510016, 0.0050576, 0.00426369, 0.0062093,
1027+
0.00333269, 0.0028687, 0.00341253, 0.00239755, 0.00270901, 0.00212149, 0.00214145, 0.00189401,
1028+
0.00165712, 0.00195088, 0.00122213, 0.00170872, 0.00156409, 0.0010485, 0.00186652, 0.00133586,
1029+
0.000825546, 0.000708795, 0.000692977, 0.000509564, 0.000440266, 0.000958493, 0.000482824,
1030+
0.000674523, 0.000467759, 0.0002561, 0.000245931, 0.000299788, 0.000300164, 0.000248568,
1031+
0.000259113, 0.000293385, 0.000116752, 0.000159686, 0.000109972, 7.83365e-05, 0.000136336,
1032+
0.000122777, 6.2142e-05, 5.4233e-05, 0.000432357, 5.34797e-05, 0.000109219, 9.98037e-05,
1033+
4.1428e-05, 4.33111e-05, 3.65319e-05, 4.29344e-05, 2.89996e-05, 2.78697e-05, 3.99215e-05,
1034+
4.1428e-05, 1.80777e-05, 5.95056e-05, 2.89996e-05, 3.42722e-05, 3.20125e-05, 5.15967e-05,
1035+
0.000418046, 2.93762e-05, 4.10514e-05, 2.97528e-05, 1.88309e-05, 2.0714e-05, 1.7701e-05,
1036+
2.14672e-05, 1.80777e-05, 2.59866e-05, 2.10906e-05, 2.44802e-05, 0.000169101, 1.7701e-05,
1037+
1.43115e-05, 1.2805e-05, 1.01687e-05, 9.41545e-06, 7.90898e-06, 9.03883e-06, 1.05453e-05,
1038+
1.09219e-05, 9.41545e-06, 9.79207e-06, 7.90898e-06, 1.39349e-05, 1.09219e-05, 9.79207e-06,
1039+
9.79207e-06, 1.09219e-05, 1.05453e-05, 1.2805e-05, 6.02589e-06, 1.46881e-05, 1.12985e-05,
1040+
1.5818e-05, 2.03374e-05, 1.54413e-05, 2.63633e-05, 2.33503e-05, 1.65712e-05, 1.7701e-05,
1041+
2.44802e-05, 1.39349e-05, 1.39349e-05, 2.18438e-05, 2.52334e-05, 1.88309e-05, 1.65712e-05,
1042+
2.29737e-05, 2.44802e-05, 1.31816e-05, 1.84543e-05, 1.80777e-05, 9.79207e-06, 1.12985e-05,
1043+
1.12985e-05, 8.28559e-06, 6.4025e-06, 6.77912e-06, 6.4025e-06, 5.64927e-06, 4.51941e-06,
1044+
6.77912e-06, 4.1428e-06, 6.02589e-06, 5.27265e-06, 7.15574e-06, 6.77912e-06, 6.02589e-06,
1045+
3.76618e-06, 6.4025e-06, 3.01294e-06, 5.27265e-06, 3.76618e-06, 4.51941e-06, 3.76618e-06,
1046+
6.77912e-06, 3.38956e-06, 6.02589e-06, 4.89603e-06, 5.27265e-06, 6.02589e-06, 5.27265e-06,
1047+
5.27265e-06, 7.90898e-06, 4.89603e-06, 1.09219e-05, 4.89603e-06, 9.41545e-06, 7.15574e-06,
1048+
8.66221e-06, 4.89603e-06, 8.28559e-06, 7.53236e-06, 8.28559e-06, 4.51941e-06, 1.05453e-05,
1049+
6.4025e-06, 1.01687e-05, 6.4025e-06, 9.03883e-06, 6.02589e-06, 9.03883e-06, 5.64927e-06,
1050+
7.53236e-06, 3.01294e-06, 6.02589e-06, 3.38956e-06, 5.27265e-06, 5.27265e-06, 5.27265e-06,
1051+
3.38956e-06, 4.89603e-06, 3.01294e-06, 4.89603e-06, 3.01294e-06, 6.02589e-06, 3.38956e-06,
1052+
9.41545e-06, 3.38956e-06, 5.64927e-06, 1.50647e-06, 6.77912e-06, 1.88309e-06, 4.51941e-06,
1053+
1.88309e-06, 4.89603e-06, 3.38956e-06, 4.89603e-06, 2.63633e-06, 9.41545e-06, 3.01294e-06,
1054+
4.51941e-06, 5.27265e-06, 6.02589e-06, 3.76618e-06, 4.89603e-06, 1.88309e-06, 4.89603e-06,
1055+
1.88309e-06, 4.89603e-06, 2.63633e-06, 5.64927e-06, 3.76618e-06, 5.64927e-06, 7.53236e-06,
1056+
7.15574e-06, 2.25971e-06, 4.89603e-06, 2.63633e-06, 2.63633e-06, 3.76618e-07, 2.25971e-06,
1057+
0, 2.41035e-05, 0, 0};
1058+
1059+
// That's like top-1m above, but it's a compilation of 11,640,340 domains coming from varous
1060+
// blocklists and zone dumps. It it relevant? No. But it's 200 MiB of domain names :-)
1061+
//
1062+
const double DNSTailNameLenProbability[256] = { 0, 0, 2.04461e-05, 1.88139e-05, 4.38991e-05,
1063+
0.000415452, 0.00569829, 0.0195254, 0.0315039, 0.0517829, 0.0780355, 0.0819671, 0.0884572,
1064+
0.0811914, 0.0755655, 0.0658041, 0.0581139, 0.0488786, 0.0419683, 0.0357179, 0.0302831, 0.024542,
1065+
0.0216147, 0.0177761, 0.0156073, 0.0128184, 0.0108588, 0.0111896, 0.00917052, 0.00945325,
1066+
0.00958932, 0.00751825, 0.0058762, 0.00448535, 0.00375255, 0.00332044, 0.00331898, 0.00344157,
1067+
0.00232004, 0.00294519, 0.00238395, 0.00197804, 0.00168139, 0.00206695, 0.00134214, 0.00115512,
1068+
0.00108846, 0.000968786, 0.000897998, 0.000961656, 0.000778156, 0.0007913, 0.000670513,
1069+
0.000639242, 0.000693622, 0.00056665, 0.000409352, 0.000364251, 0.000445176, 0.000279631,
1070+
0.0002658, 0.00037224, 0.000240801, 0.00026013, 0.000214599, 0.000126199, 0.000117265,
1071+
0.000129549, 0.000132127, 0.000105581, 9.95675e-05, 0.000108674, 5.30053e-05, 9.50144e-05,
1072+
0.000114172, 4.16654e-05, 7.65442e-05, 4.66481e-05, 2.96383e-05, 2.76624e-05, 0.000113485,
1073+
2.02743e-05, 0.00057988, 0.000310042, 1.67521e-05, 1.57212e-05, 1.25426e-05, 1.3058e-05,
1074+
1.37453e-05, 1.05667e-05, 1.34876e-05, 1.31439e-05, 0.000549898, 0.000296039, 1.51198e-05,
1075+
1.09103e-05, 1.09103e-05, 1.62366e-05, 0.000101715, 8.67672e-06, 1.15976e-05, 9.62171e-06,
1076+
6.09948e-06, 6.52902e-06, 9.36399e-06, 6.01357e-06, 6.18539e-06, 9.36399e-06, 5.75585e-06,
1077+
6.52902e-06, 3.91741e-05, 5.3263e-06, 4.2095e-06, 6.78674e-06, 2.74906e-06, 3.26451e-06,
1078+
2.1477e-06, 3.1786e-06, 3.43633e-06, 5.15449e-06, 3.00679e-06, 3.1786e-06, 2.23361e-06,
1079+
4.12359e-06, 3.1786e-06, 3.09269e-06, 3.95177e-06, 3.52223e-06, 3.00679e-06, 3.43633e-06,
1080+
1.97589e-06, 4.03768e-06, 3.1786e-06, 4.63904e-06, 4.98267e-06, 4.12359e-06, 6.61493e-06,
1081+
5.92766e-06, 4.38132e-06, 4.89676e-06, 6.44311e-06, 4.46722e-06, 3.77996e-06, 5.41221e-06,
1082+
5.84175e-06, 4.89676e-06, 4.55313e-06, 5.84175e-06, 5.84175e-06, 3.60814e-06, 4.98267e-06,
1083+
4.63904e-06, 3.00679e-06, 3.00679e-06, 2.74906e-06, 2.23361e-06, 2.1477e-06, 2.31952e-06,
1084+
1.88998e-06, 1.71816e-06, 1.63225e-06, 2.31952e-06, 1.11681e-06, 1.71816e-06, 1.37453e-06,
1085+
1.97589e-06, 1.63225e-06, 1.97589e-06, 1.46044e-06, 2.0618e-06, 6.87265e-07, 1.63225e-06,
1086+
1.46044e-06, 1.46044e-06, 1.28862e-06, 2.1477e-06, 1.11681e-06, 1.80407e-06, 1.20271e-06,
1087+
1.63225e-06, 1.37453e-06, 1.63225e-06, 1.37453e-06, 2.31952e-06, 1.28862e-06, 3.09269e-06,
1088+
1.80407e-06, 2.74906e-06, 2.0618e-06, 2.40543e-06, 1.28862e-06, 2.1477e-06, 2.0618e-06,
1089+
2.23361e-06, 1.37453e-06, 2.83497e-06, 1.63225e-06, 2.49134e-06, 1.97589e-06, 2.31952e-06,
1090+
1.54635e-06, 2.31952e-06, 1.46044e-06, 1.88998e-06, 8.59081e-07, 1.46044e-06, 8.59081e-07,
1091+
1.63225e-06, 1.63225e-06, 1.28862e-06, 1.0309e-06, 1.28862e-06, 8.59081e-07, 1.37453e-06,
1092+
7.73173e-07, 1.54635e-06, 9.4499e-07, 2.23361e-06, 7.73173e-07, 1.46044e-06, 3.43633e-07,
1093+
1.80407e-06, 6.01357e-07, 1.28862e-06, 7.73173e-07, 1.37453e-06, 8.59081e-07, 1.28862e-06,
1094+
7.73173e-07, 2.31952e-06, 7.73173e-07, 1.11681e-06, 1.20271e-06, 1.63225e-06, 9.4499e-07,
1095+
1.20271e-06, 4.29541e-07, 1.20271e-06, 5.15449e-07, 1.37453e-06, 6.01357e-07, 1.37453e-06,
1096+
8.59081e-07, 1.37453e-06, 1.71816e-06, 1.80407e-06, 6.01357e-07, 1.37453e-06, 6.01357e-07,
1097+
6.87265e-07, 1.71816e-07, 6.01357e-07, 0, 5.92766e-06, 0, 0};
1098+
1099+
// This distribution comes from https://github.com/backtrace-labs/umash/wiki/Execution-traces
1100+
// startup-1M.2020-08-28.trace.bz2 file has 1,000,000 umash_full() samples of key lengths.
1101+
// Two other files have boring distribution for umash_full: startup-tail-1M.2020-08-28.trace.bz2
1102+
// has 99.9974% lines with "arg4=65" and steady-state.2020-08-28.trace.bz2 is not that less boring:
1103+
// len=4 for 5.5%, len=64 for 85.4%, and len=65 for 9.1% lines.
1104+
const double UMashStartHeadProbability[256] = { 0, 7e-06, 5.1e-05, 0.000396, 0.001312, 0.00311,
1105+
0.005616, 0.007887, 0.011145, 0.068172, 0.014618, 0.01667, 0.009502, 0.008275, 0.007444, 0.008088,
1106+
0.105451, 0.000246, 0.0001, 0.000117, 0.000116, 0.000487, 0.000367, 0.000179, 0.000293, 5.8e-05,
1107+
5.6e-05, 0.000124, 0.000191, 0.00034, 0.000323, 0.000333, 0.000303, 0.000274, 0.000238, 0.000202,
1108+
0.000246, 0.409961, 0.000235, 0.010119, 0.000239, 0.000171, 0.000128, 0.0001, 0.005217, 5.1e-05,
1109+
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,
1110+
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,
1111+
5.7e-05, 0.000101, 0.000316, 0.000961, 0.001873, 0.001714, 0.00029, 8.8e-05, 0.000185, 0.0006,
1112+
0.001038, 0.001762, 0.003228, 0.003174, 0.000284, 0.000266, 0.000292, 0.000752, 0.001381,
1113+
0.001331, 0.000145, 0.000161, 0.000177, 0.001517, 0.000304, 0.000176, 0.009464, 0.000342,
1114+
0.001809, 0.000286, 0.000962, 0.000116, 0.00039, 0.000383, 0.000244, 5e-05, 5.4e-05, 4.6e-05,
1115+
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,
1116+
0.000189, 0.000902, 6e-05, 0.003476, 0.044543, 0.000275, 0.00596, 5.8e-05, 0.001705, 8.4e-05,
1117+
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,
1118+
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,
1119+
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,
1120+
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,
1121+
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,
1122+
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,
1123+
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,
1124+
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,
1125+
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,
1126+
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,
1127+
2e-06, 1.6e-05, 5e-06, 6e-06, 8e-06, 0, 4e-06};
1128+
1129+
static std::pair<double, double> CalcWAvg(const double *x, const double *dist, size_t imin, size_t imax)
1130+
{
1131+
double sum = 0, prb = 0;
1132+
for (size_t i = imin; i <= imax; i++) {
1133+
sum += dist[i] * x[i];
1134+
prb += dist[i];
1135+
}
1136+
sum /= prb;
1137+
return std::make_pair(sum, prb);
1138+
}
1139+
9821140
template < typename hashtype >
9831141
void test ( hashfunc<hashtype> hash, HashInfo* info )
9841142
{
@@ -1027,7 +1185,6 @@ void test ( hashfunc<hashtype> hash, HashInfo* info )
10271185

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

10521209
if (g_testSpeedSmall || g_testAll) {
1053-
const char* const envsmin = getenv("SMHASHER_SMALLKEY_MIN");
1054-
const char* const envsmax = getenv("SMHASHER_SMALLKEY_MAX");
1055-
const int minkey = max(min(envsmin ? atoi(envsmin) : 1, 255), 1);
1056-
const int maxkey = max(min(envsmax ? atoi(envsmax) : 32, 255), minkey);
1210+
const int dflmax = g_testExtra ? 64 : 32;
1211+
const int minkey = getenvlong("SMHASHER_SMALLKEY_MIN", 1, 1, TIMEHASH_SMALL_LEN_MAX);
1212+
const int maxkey = getenvlong("SMHASHER_SMALLKEY_MAX", minkey, dflmax, TIMEHASH_SMALL_LEN_MAX);
1213+
double cph[TIMEHASH_SMALL_LEN_MAX + 1];
10571214
for(int i = minkey; i <= maxkey; i++)
10581215
{
10591216
volatile int j = i;
1060-
sum += TinySpeedTest(hashfunc<hashtype>(info->hash),sizeof(hashtype),j,info->verification,true);
1217+
cph[j] = TinySpeedTest(hashfunc<hashtype>(info->hash),sizeof(hashtype),j,info->verification,true);
1218+
}
1219+
{
1220+
double sum = 0;
1221+
for (int i = minkey; i <= maxkey; i++)
1222+
sum += cph[i];
1223+
sum /= (maxkey - minkey + 1);
1224+
g_speed = sum;
1225+
printf("Average %8.3f cycles/hash\n",sum);
1226+
}
1227+
{
1228+
static_assert(COUNT_OF(cph) <= COUNT_OF(DNSQueryLenProbability));
1229+
const auto q = CalcWAvg(cph, DNSQueryLenProbability, minkey, maxkey);
1230+
printf("Average DNS query (|%5.1f%% of query.log) %8.3f cycles/hash\n",100.*q.second,q.first);
1231+
}
1232+
{
1233+
static_assert(COUNT_OF(cph) <= COUNT_OF(DNSTopNameLenProbability));
1234+
const auto m = CalcWAvg(cph, DNSTopNameLenProbability, minkey, maxkey);
1235+
printf("Average DNS name (|%5.1f%% of top-1m.csv) %8.3f cycles/hash\n",100.*m.second,m.first);
1236+
}
1237+
{
1238+
static_assert(COUNT_OF(cph) <= COUNT_OF(DNSTailNameLenProbability));
1239+
const auto d = CalcWAvg(cph, DNSTailNameLenProbability, minkey, maxkey);
1240+
printf("Average DNS name (|%5.1f%% of 200MiB.zone)%8.3f cycles/hash\n",100.*d.second,d.first);
1241+
}
1242+
{
1243+
static_assert(COUNT_OF(cph) <= COUNT_OF(UMashStartHeadProbability));
1244+
const auto u = CalcWAvg(cph, UMashStartHeadProbability, minkey, maxkey);
1245+
printf("Average UMASH (|%5.1f%% of startup-1M.bz2)%8.3f cycles/hash\n",100.*u.second,u.first);
10611246
}
1062-
g_speed = sum = sum / (maxkey - minkey + 1);
1063-
printf("Average %6.3f cycles/hash\n",sum);
10641247
printf("\n");
10651248
fflush(NULL);
10661249
}

0 commit comments

Comments
 (0)