Skip to content

Commit

Permalink
Split Speed into SpeedBulk and SpeedSmall, add ENV{SMHASHER_SMALLKEY_…
Browse files Browse the repository at this point in the history
…MAX}

It adds SMHASHER_SMALLKEY_MAX environment variable to override default
value of the longest "Small key" for hash and changes default value from
31 to 32 to make the Average a bit more fair to the hashes reading the
memory word-by-word (dword, qword) and not byte-by-byte.

SMHASHER_SMALLKEY_MIN is also added as a counterpart to benchmark hashes
when the range of small key lengths is known.
  • Loading branch information
darkk committed Aug 30, 2024
1 parent 6888dd3 commit 0c6a1ef
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ bool g_testExtra = false; // excessive torture tests: Sparse, Avalanche, D
bool g_testVerifyAll = false;

bool g_testSanity = false;
bool g_testSpeed = false;
bool g_testSpeedAll = false;
bool g_testSpeedBulk = false;
bool g_testSpeedSmall = false;
bool g_testHashmap = false;
bool g_testAvalanche = false;
bool g_testSparse = false;
Expand Down Expand Up @@ -56,7 +58,9 @@ TestOpts g_testopts[] =
{ g_testAll, "All" },
{ g_testVerifyAll, "VerifyAll" },
{ g_testSanity, "Sanity" },
{ g_testSpeed, "Speed" },
{ g_testSpeedAll, "Speed" },
{ g_testSpeedBulk, "SpeedBulk" },
{ g_testSpeedSmall, "SpeedSmall" },
{ g_testHashmap, "Hashmap" },
{ g_testAvalanche, "Avalanche" },
{ g_testSparse, "Sparse" },
Expand Down Expand Up @@ -997,7 +1001,7 @@ void test ( hashfunc<hashtype> hash, HashInfo* info )
printf("PASS\n\n"); fflush(NULL); // if not it does exit(1)
}

if (g_testAll || g_testSpeed || g_testHashmap) {
if (g_testAll || g_testSpeedBulk || g_testSpeedSmall || g_testHashmap) {
printf("--- Testing %s \"%s\" %s\n\n", info->name, info->desc, quality_str[info->quality]);
} else {
fprintf(stderr, "--- Testing %s \"%s\" %s\n\n", info->name, info->desc, quality_str[info->quality]);
Expand All @@ -1021,7 +1025,7 @@ void test ( hashfunc<hashtype> hash, HashInfo* info )
//-----------------------------------------------------------------------------
// Speed tests

if(g_testSpeed || g_testAll)
if(g_testSpeedBulk || g_testSpeedSmall || g_testAll)
{
double sum = 0.0;
printf("[[[ Speed Tests ]]]\n\n");
Expand All @@ -1038,19 +1042,28 @@ void test ( hashfunc<hashtype> hash, HashInfo* info )
fflush(NULL);

Seed_init (info, info->verification);
BulkSpeedTest(info->hash,info->verification);
printf("\n");
fflush(NULL);

for(int i = 1; i < 32; i++)
{
volatile int j = i;
sum += TinySpeedTest(hashfunc<hashtype>(info->hash),sizeof(hashtype),j,info->verification,true);
if (g_testSpeedBulk || g_testAll) {
BulkSpeedTest(info->hash,info->verification);
printf("\n");
fflush(NULL);
}

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);
for(int i = minkey; i <= maxkey; i++)
{
volatile int j = i;
sum += TinySpeedTest(hashfunc<hashtype>(info->hash),sizeof(hashtype),j,info->verification,true);
}
g_speed = sum = sum / (maxkey - minkey + 1);
printf("Average %6.3f cycles/hash\n",sum);
printf("\n");
fflush(NULL);
}
g_speed = sum = sum / 31.0;
printf("Average %6.3f cycles/hash\n",sum);
printf("\n");
fflush(NULL);
} else {
// known slow hashes (> 500), cycle/hash
const struct { pfHash h; double cycles; } speeds[] = {
Expand Down Expand Up @@ -2786,6 +2799,8 @@ int main ( int argc, const char ** argv )
// Not a command ? => interpreted as hash name
hashToTest = arg;
}
if (g_testSpeedAll)
g_testSpeedBulk = g_testSpeedSmall = true;

// Code runs on the 3rd CPU by default? only for speed tests
//SetAffinity((1 << 2));
Expand Down

0 comments on commit 0c6a1ef

Please sign in to comment.