tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 1 | #include <stdio.h>
|
| 2 |
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 3 | #include "hashes.h"
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 4 | #include "KeysetTest.h"
|
| 5 | #include "SpeedTest.h"
|
| 6 | #include "AvalancheTest.h"
|
| 7 | #include "DifferentialTest.h"
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 8 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 9 | #include <time.h>
|
| 10 | #include <intrin.h>
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 11 | #include <windows.h>
|
| 12 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 13 | #pragma warning(disable : 4127) // "conditional expression is constant" in the if()s for avalanchetest
|
| 14 |
|
| 15 | bool g_testAll = false;
|
| 16 |
|
| 17 | /*
|
| 18 | bool g_testSanity = true;
|
| 19 | bool g_testSpeed = true;
|
| 20 | bool g_testDiff = true;
|
| 21 | bool g_testAvalanche = true;
|
| 22 | bool g_testCyclic = true;
|
| 23 | bool g_testSparse = true;
|
| 24 | bool g_testPermutation = true;
|
| 25 | bool g_testWindow = true;
|
| 26 | bool g_testText = true;
|
| 27 | bool g_testZeroes = true;
|
| 28 | bool g_testSeed = true;
|
| 29 | */
|
| 30 |
|
| 31 | //*
|
| 32 | bool g_testSanity = false;
|
| 33 | bool g_testSpeed = false;
|
| 34 | bool g_testDiff = false;
|
| 35 | bool g_testAvalanche = false;
|
| 36 | bool g_testCyclic = false;
|
| 37 | bool g_testSparse = false;
|
| 38 | bool g_testPermutation = false;
|
| 39 | bool g_testWindow = false;
|
| 40 | bool g_testText = false;
|
| 41 | bool g_testZeroes = false;
|
| 42 | bool g_testSeed = false;
|
| 43 | //*/
|
| 44 |
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 45 |
|
| 46 | int64_t g_hashcount = 0;
|
| 47 | int64_t g_bytecount = 0;
|
| 48 |
|
| 49 | void counterhash ( const void * , const int len, const uint32_t , void * out )
|
| 50 | {
|
| 51 | g_hashcount++;
|
| 52 | g_bytecount += len;
|
| 53 |
|
| 54 | *(uint32_t*)out = rand_u32();
|
| 55 | }
|
| 56 |
|
| 57 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 58 | //-----------------------------------------------------------------------------
|
| 59 |
|
| 60 | struct HashInfo
|
| 61 | {
|
| 62 | pfHash hash;
|
| 63 | int hashbits;
|
| 64 | const char * name;
|
| 65 | const char * desc;
|
| 66 | };
|
| 67 |
|
| 68 | HashInfo g_hashes[] =
|
| 69 | {
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 70 | { counterhash, 32, "count", "Counts how many times the hash function is called" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 71 | { randhash_32, 32, "rand32", "Random number generator, 32-bit" },
|
| 72 | { randhash_64, 64, "rand64", "Random number generator, 64-bit" },
|
| 73 | { randhash_128, 128, "rand128", "Random number generator, 128-bit" },
|
| 74 |
|
| 75 | { crc32, 32, "crc32", "CRC-32" },
|
| 76 | { DoNothingHash, 32, "donothing32", "Do-Nothing Function (only valid for speed test comparison)" },
|
| 77 |
|
| 78 | { md5_32, 32, "md5_32a", "MD5, first 32 bits of result" },
|
| 79 | { sha1_32a, 32, "sha1_32a", "SHA1, first 32 bits of result" },
|
| 80 |
|
| 81 | { FNV, 32, "FNV", "Fowler-Noll-Vo hash, 32-bit" },
|
| 82 | { lookup3_test, 32, "lookup3", "Bob Jenkins' lookup3" },
|
| 83 | { SuperFastHash, 32, "superfast", "Paul Hsieh's SuperFastHash" },
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 84 | { MurmurOAAT, 32, "MurmurOAAT", "Murmur one-at-a-time" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 85 |
|
| 86 | // MurmurHash2
|
| 87 |
|
| 88 | { MurmurHash2_test, 32, "Murmur2", "MurmurHash2 for x86, 32-bit" },
|
| 89 | { MurmurHash2A_test, 32, "Murmur2A", "MurmurHash2A for x86, 32-bit" },
|
| 90 | { MurmurHash64A_test, 64, "Murmur2B", "MurmurHash2 for x64, 64-bit" },
|
| 91 | { MurmurHash64B_test, 64, "Murmur2C", "MurmurHash2 for x86, 64-bit" },
|
| 92 |
|
| 93 | // MurmurHash3
|
| 94 |
|
| 95 | { MurmurHash3_x86_32, 32, "Murmur3A", "MurmurHash3 for x86, 32-bit" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 96 | { MurmurHash3_x86_128, 128, "Murmur3C", "MurmurHash3 for x86, 128-bit" },
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 97 | { MurmurHash3_x64_128, 128, "Murmur3F", "MurmurHash3 for x64, 128-bit" },
|
| 98 |
|
| 99 | };
|
| 100 |
|
| 101 | HashInfo * findHash ( const char * name )
|
| 102 | {
|
| 103 | for(int i = 0; i < sizeof(g_hashes) / sizeof(HashInfo); i++)
|
| 104 | {
|
| 105 | if(_stricmp(name,g_hashes[i].name) == 0) return &g_hashes[i];
|
| 106 | }
|
| 107 |
|
| 108 | return NULL;
|
| 109 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 110 |
|
| 111 | //----------------------------------------------------------------------------
|
| 112 |
|
| 113 | template < typename hashtype >
|
| 114 | void test ( hashfunc<hashtype> hash, const char * hashname )
|
| 115 | {
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 116 | const int hashbits = sizeof(hashtype) * 8;
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 117 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 118 | printf("-------------------------------------------------------------------------------\n");
|
| 119 | printf("--- Testing %s\n\n",hashname);
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 120 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 121 | //-----------------------------------------------------------------------------
|
| 122 | // Sanity tests
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 123 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 124 | if(g_testSanity || g_testAll)
|
| 125 | {
|
| 126 | printf("[[[ Sanity Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 127 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 128 | QuickBrownFox(hash,hashbits);
|
| 129 | SanityTest(hash,hashbits);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 130 | AppendedZeroesTest(hash,hashbits);
|
| 131 | printf("\n");
|
| 132 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 133 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 134 | //-----------------------------------------------------------------------------
|
| 135 | // Speed tests
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 136 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 137 | if(g_testSpeed || g_testAll)
|
| 138 | {
|
| 139 | printf("[[[ Speed Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 140 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 141 | BulkSpeedTest(hash);
|
| 142 | printf("\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 143 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 144 | for(int i = 1; i < 32; i++)
|
| 145 | {
|
| 146 | double cycles;
|
| 147 |
|
| 148 | TinySpeedTest(hash,sizeof(hashtype),i,true,cycles);
|
| 149 | }
|
| 150 |
|
| 151 | for(int i = 32; i <= 2048; i += 32)
|
| 152 | {
|
| 153 | double cycles;
|
| 154 |
|
| 155 |
|
| 156 | TinySpeedTest(hash,sizeof(hashtype),i,true,cycles);
|
| 157 | }
|
| 158 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 159 | printf("\n");
|
| 160 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 161 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 162 | //-----------------------------------------------------------------------------
|
| 163 | // Differential tests
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 164 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 165 | if(g_testDiff || g_testAll)
|
| 166 | {
|
| 167 | printf("[[[ Differential Tests ]]]\n\n");
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 168 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 169 | bool result = true;
|
| 170 | bool dumpCollisions = false;
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 171 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 172 | result &= DiffTest< Blob<64>, hashtype >(hash,5,1000,dumpCollisions);
|
| 173 | result &= DiffTest< Blob<128>, hashtype >(hash,4,1000,dumpCollisions);
|
| 174 | result &= DiffTest< Blob<256>, hashtype >(hash,3,1000,dumpCollisions);
|
| 175 |
|
| 176 | if(!result) printf("*********FAIL*********\n");
|
| 177 | printf("\n");
|
| 178 | }
|
| 179 |
|
| 180 | //-----------------------------------------------------------------------------
|
| 181 | // Avalanche tests.
|
| 182 |
|
| 183 | // 2 million reps is enough to measure bias down to ~0.25%
|
| 184 |
|
| 185 | if(g_testAvalanche || g_testAll)
|
| 186 | {
|
| 187 | printf("[[[ Avalanche Tests ]]]\n\n");
|
| 188 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 189 | //const int hashbits = sizeof(hashtype) * 8;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 190 | bool result = true;
|
| 191 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 192 | result &= AvalancheTest< Blob< 32>, hashtype > (hash,300000);
|
| 193 | result &= AvalancheTest< Blob< 40>, hashtype > (hash,300000);
|
| 194 | result &= AvalancheTest< Blob< 48>, hashtype > (hash,300000);
|
| 195 | result &= AvalancheTest< Blob< 56>, hashtype > (hash,300000);
|
| 196 |
|
| 197 | result &= AvalancheTest< Blob< 64>, hashtype > (hash,300000);
|
| 198 | result &= AvalancheTest< Blob< 72>, hashtype > (hash,300000);
|
| 199 | result &= AvalancheTest< Blob< 80>, hashtype > (hash,300000);
|
| 200 | result &= AvalancheTest< Blob< 88>, hashtype > (hash,300000);
|
| 201 | result &= AvalancheTest< Blob< 96>, hashtype > (hash,300000);
|
| 202 | result &= AvalancheTest< Blob<104>, hashtype > (hash,300000);
|
| 203 | result &= AvalancheTest< Blob<112>, hashtype > (hash,300000);
|
| 204 | result &= AvalancheTest< Blob<120>, hashtype > (hash,300000);
|
| 205 |
|
| 206 | result &= AvalancheTest< Blob<128>, hashtype > (hash,300000);
|
| 207 | result &= AvalancheTest< Blob<136>, hashtype > (hash,300000);
|
| 208 | result &= AvalancheTest< Blob<144>, hashtype > (hash,300000);
|
| 209 | result &= AvalancheTest< Blob<152>, hashtype > (hash,300000);
|
| 210 | result &= AvalancheTest< Blob<160>, hashtype > (hash,300000);
|
| 211 | result &= AvalancheTest< Blob<168>, hashtype > (hash,300000);
|
| 212 | result &= AvalancheTest< Blob<176>, hashtype > (hash,300000);
|
| 213 | result &= AvalancheTest< Blob<184>, hashtype > (hash,300000);
|
| 214 | result &= AvalancheTest< Blob<192>, hashtype > (hash,300000);
|
| 215 | result &= AvalancheTest< Blob<200>, hashtype > (hash,300000);
|
| 216 | result &= AvalancheTest< Blob<208>, hashtype > (hash,300000);
|
| 217 | result &= AvalancheTest< Blob<216>, hashtype > (hash,300000);
|
| 218 | result &= AvalancheTest< Blob<224>, hashtype > (hash,300000);
|
| 219 | result &= AvalancheTest< Blob<232>, hashtype > (hash,300000);
|
| 220 | result &= AvalancheTest< Blob<240>, hashtype > (hash,300000);
|
| 221 | result &= AvalancheTest< Blob<248>, hashtype > (hash,300000);
|
| 222 |
|
| 223 | result &= AvalancheTest< Blob<256>, hashtype > (hash,300000);
|
| 224 |
|
| 225 | //result &= AvalancheTest< Blob<hashbits * 2>, hashtype > (hash,200000);
|
| 226 | //result &= AvalancheTest< Blob<768>, hashtype > (hash,2000000);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 227 |
|
| 228 | // The bit independence test is slow and not particularly useful...
|
| 229 | //result &= BicTest < Blob<hashbits * 2>, hashtype > ( hash, 1000000 );
|
| 230 |
|
| 231 | if(!result) printf("*********FAIL*********\n");
|
| 232 | printf("\n");
|
| 233 | }
|
| 234 |
|
| 235 | //-----------------------------------------------------------------------------
|
| 236 | // Keyset 'Cyclic'
|
| 237 |
|
| 238 | if(g_testCyclic || g_testAll)
|
| 239 | {
|
| 240 | printf("[[[ Keyset 'Cyclic' Tests ]]]\n\n");
|
| 241 |
|
| 242 | bool result = true;
|
| 243 | bool drawDiagram = false;
|
| 244 |
|
| 245 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+0,8,10000000,drawDiagram);
|
| 246 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+1,8,10000000,drawDiagram);
|
| 247 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+2,8,10000000,drawDiagram);
|
| 248 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+3,8,10000000,drawDiagram);
|
| 249 | result &= CyclicKeyTest<hashtype>(hash,sizeof(hashtype)+4,8,10000000,drawDiagram);
|
| 250 |
|
| 251 | if(!result) printf("*********FAIL*********\n");
|
| 252 | printf("\n");
|
| 253 | }
|
| 254 |
|
| 255 | //-----------------------------------------------------------------------------
|
| 256 | // Keyset 'Sparse'
|
| 257 |
|
| 258 | if(g_testSparse || g_testAll)
|
| 259 | {
|
| 260 | printf("[[[ Keyset 'Sparse' Tests ]]]\n\n");
|
| 261 |
|
| 262 | bool result = true;
|
| 263 | bool drawDiagram = false;
|
| 264 |
|
| 265 | result &= SparseKeyTest< 32,hashtype>(hash,6,true,true,true,drawDiagram);
|
| 266 | result &= SparseKeyTest< 40,hashtype>(hash,6,true,true,true,drawDiagram);
|
| 267 | result &= SparseKeyTest< 48,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 268 | result &= SparseKeyTest< 56,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 269 | result &= SparseKeyTest< 64,hashtype>(hash,5,true,true,true,drawDiagram);
|
| 270 | result &= SparseKeyTest< 96,hashtype>(hash,4,true,true,true,drawDiagram);
|
| 271 | result &= SparseKeyTest< 256,hashtype>(hash,3,true,true,true,drawDiagram);
|
| 272 | result &= SparseKeyTest<2048,hashtype>(hash,2,true,true,true,drawDiagram);
|
| 273 |
|
| 274 | if(!result) printf("*********FAIL*********\n");
|
| 275 | printf("\n");
|
| 276 | }
|
| 277 |
|
| 278 | //-----------------------------------------------------------------------------
|
| 279 | // Keyset 'Permutation'
|
| 280 |
|
| 281 | if(g_testPermutation || g_testAll)
|
| 282 | {
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 283 | {
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 284 | // This one breaks lookup3, surprisingly
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 285 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 286 | printf("[[[ Keyset 'Combination Lowbits' Tests ]]]\n\n");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 287 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 288 | bool result = true;
|
| 289 | bool drawDiagram = false;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 290 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 291 | uint32_t blocks[] =
|
| 292 | {
|
| 293 | 0x00000000,
|
| 294 |
|
| 295 | 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007,
|
| 296 | };
|
| 297 |
|
| 298 | result &= CombinationKeyTest<hashtype>(hash,8,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 299 |
|
| 300 | if(!result) printf("*********FAIL*********\n");
|
| 301 | printf("\n");
|
| 302 | }
|
| 303 |
|
| 304 | {
|
| 305 | printf("[[[ Keyset 'Combination Highbits' Tests ]]]\n\n");
|
| 306 |
|
| 307 | bool result = true;
|
| 308 | bool drawDiagram = false;
|
| 309 |
|
| 310 | uint32_t blocks[] =
|
| 311 | {
|
| 312 | 0x00000000,
|
| 313 |
|
| 314 | 0x20000000, 0x40000000, 0x60000000, 0x80000000, 0xA0000000, 0xC0000000, 0xE0000000
|
| 315 | };
|
| 316 |
|
| 317 | result &= CombinationKeyTest<hashtype>(hash,8,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 318 |
|
| 319 | if(!result) printf("*********FAIL*********\n");
|
| 320 | printf("\n");
|
| 321 | }
|
| 322 |
|
| 323 | {
|
| 324 | printf("[[[ Keyset 'Combination 0x8000000' Tests ]]]\n\n");
|
| 325 |
|
| 326 | bool result = true;
|
| 327 | bool drawDiagram = false;
|
| 328 |
|
| 329 | uint32_t blocks[] =
|
| 330 | {
|
| 331 | 0x00000000,
|
| 332 |
|
| 333 | 0x80000000,
|
| 334 | };
|
| 335 |
|
| 336 | result &= CombinationKeyTest<hashtype>(hash,20,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 337 |
|
| 338 | if(!result) printf("*********FAIL*********\n");
|
| 339 | printf("\n");
|
| 340 | }
|
| 341 |
|
| 342 | {
|
| 343 | printf("[[[ Keyset 'Combination 0x0000001' Tests ]]]\n\n");
|
| 344 |
|
| 345 | bool result = true;
|
| 346 | bool drawDiagram = false;
|
| 347 |
|
| 348 | uint32_t blocks[] =
|
| 349 | {
|
| 350 | 0x00000000,
|
| 351 |
|
| 352 | 0x00000001,
|
| 353 | };
|
| 354 |
|
| 355 | result &= CombinationKeyTest<hashtype>(hash,20,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 356 |
|
| 357 | if(!result) printf("*********FAIL*********\n");
|
| 358 | printf("\n");
|
| 359 | }
|
| 360 |
|
| 361 | {
|
| 362 | printf("[[[ Keyset 'Combination Hi-Lo' Tests ]]]\n\n");
|
| 363 |
|
| 364 | bool result = true;
|
| 365 | bool drawDiagram = false;
|
| 366 |
|
| 367 | uint32_t blocks[] =
|
| 368 | {
|
| 369 | 0x00000000,
|
| 370 |
|
| 371 | 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006, 0x00000007,
|
| 372 |
|
| 373 | 0x80000000, 0x40000000, 0xC0000000, 0x20000000, 0xA0000000, 0x60000000, 0xE0000000
|
| 374 | };
|
| 375 |
|
| 376 | result &= CombinationKeyTest<hashtype>(hash,6,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 377 |
|
| 378 | if(!result) printf("*********FAIL*********\n");
|
| 379 | printf("\n");
|
| 380 | }
|
| 381 |
|
| 382 | //----------
|
| 383 |
|
| 384 | /*
|
| 385 | {
|
| 386 | printf("[[[ Keyset 'Permutation' Tests ]]]\n\n");
|
| 387 |
|
| 388 | bool result = true;
|
| 389 | bool drawDiagram = false;
|
| 390 |
|
| 391 | // This very sparse set of blocks is particularly hard for SuperFastHash
|
| 392 |
|
| 393 | uint32_t blocks[] =
|
| 394 | {
|
| 395 | 0x00000000,
|
| 396 | 0x00000001,
|
| 397 | 0x00000002,
|
| 398 |
|
| 399 | 0x00000400,
|
| 400 | 0x00008000,
|
| 401 |
|
| 402 | 0x00080000,
|
| 403 | 0x00200000,
|
| 404 |
|
| 405 | 0x20000000,
|
| 406 | 0x40000000,
|
| 407 | 0x80000000,
|
| 408 | };
|
| 409 |
|
| 410 | result &= PermutationKeyTest<hashtype>(hash,blocks,sizeof(blocks) / sizeof(uint32_t),true,true,drawDiagram);
|
| 411 |
|
| 412 | if(!result) printf("*********FAIL*********\n");
|
| 413 | printf("\n");
|
| 414 | }
|
| 415 | */
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 416 | }
|
| 417 |
|
| 418 | //-----------------------------------------------------------------------------
|
| 419 | // Keyset 'Window'
|
| 420 |
|
| 421 | // Skip distribution test for these - they're too easy to distribute well,
|
| 422 | // and it generates a _lot_ of testing
|
| 423 |
|
| 424 | if(g_testWindow || g_testAll)
|
| 425 | {
|
| 426 | printf("[[[ Keyset 'Window' Tests ]]]\n\n");
|
| 427 |
|
| 428 | bool result = true;
|
| 429 | bool testCollision = true;
|
| 430 | bool testDistribution = false;
|
| 431 | bool drawDiagram = false;
|
| 432 |
|
| 433 | result &= WindowedKeyTest< Blob<hashbits*2>, hashtype > ( hash, 20, testCollision, testDistribution, drawDiagram );
|
| 434 |
|
| 435 | if(!result) printf("*********FAIL*********\n");
|
| 436 | printf("\n");
|
| 437 | }
|
| 438 |
|
| 439 | //-----------------------------------------------------------------------------
|
| 440 | // Keyset 'Text'
|
| 441 |
|
| 442 | if(g_testText || g_testAll)
|
| 443 | {
|
| 444 | printf("[[[ Keyset 'Text' Tests ]]]\n\n");
|
| 445 |
|
| 446 | bool result = true;
|
| 447 | bool drawDiagram = false;
|
| 448 |
|
| 449 | const char * alnum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
| 450 |
|
| 451 | result &= TextKeyTest( hash, "Foo", alnum,4, "Bar", drawDiagram );
|
| 452 | result &= TextKeyTest( hash, "FooBar", alnum,4, "", drawDiagram );
|
| 453 | result &= TextKeyTest( hash, "", alnum,4, "FooBar", drawDiagram );
|
| 454 |
|
| 455 | if(!result) printf("*********FAIL*********\n");
|
| 456 | printf("\n");
|
| 457 | }
|
| 458 |
|
| 459 | //-----------------------------------------------------------------------------
|
| 460 | // Keyset 'Zeroes'
|
| 461 |
|
| 462 | if(g_testZeroes || g_testAll)
|
| 463 | {
|
| 464 | printf("[[[ Keyset 'Zeroes' Tests ]]]\n\n");
|
| 465 |
|
| 466 | bool result = true;
|
| 467 | bool drawDiagram = false;
|
| 468 |
|
| 469 | result &= ZeroKeyTest<hashtype>( hash, drawDiagram );
|
| 470 |
|
| 471 | if(!result) printf("*********FAIL*********\n");
|
| 472 | printf("\n");
|
| 473 | }
|
| 474 |
|
| 475 | //-----------------------------------------------------------------------------
|
| 476 | // Keyset 'Seed'
|
| 477 |
|
| 478 | if(g_testSeed || g_testAll)
|
| 479 | {
|
| 480 | printf("[[[ Keyset 'Seed' Tests ]]]\n\n");
|
| 481 |
|
| 482 | bool result = true;
|
| 483 | bool drawDiagram = false;
|
| 484 |
|
| 485 | result &= SeedTest<hashtype>( hash, 1000000, drawDiagram );
|
| 486 |
|
| 487 | if(!result) printf("*********FAIL*********\n");
|
| 488 | printf("\n");
|
| 489 | }
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 490 | }
|
| 491 |
|
| 492 | //-----------------------------------------------------------------------------
|
| 493 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 494 | void testHash ( const char * name )
|
| 495 | {
|
| 496 | HashInfo * pInfo = findHash(name);
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 497 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 498 | if(pInfo == NULL)
|
| 499 | {
|
| 500 | printf("Invalid hash '%s' specified\n",name);
|
| 501 | return;
|
| 502 | }
|
| 503 | else
|
| 504 | {
|
| 505 | if(pInfo->hashbits == 32)
|
| 506 | {
|
| 507 | test<uint32_t>( pInfo->hash, pInfo->desc );
|
| 508 | }
|
| 509 | else if(pInfo->hashbits == 64)
|
| 510 | {
|
| 511 | test<uint64_t>( pInfo->hash, pInfo->desc );
|
| 512 | }
|
| 513 | else if(pInfo->hashbits == 128)
|
| 514 | {
|
| 515 | test<uint128_t>( pInfo->hash, pInfo->desc );
|
| 516 | }
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 517 | else if(pInfo->hashbits == 256)
|
| 518 | {
|
| 519 | test<uint256_t>( pInfo->hash, pInfo->desc );
|
| 520 | }
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 521 | else
|
| 522 | {
|
| 523 | printf("Invalid hash bit width %d for hash '%s'",pInfo->hashbits,pInfo->name);
|
| 524 | }
|
| 525 | }
|
| 526 | }
|
| 527 | //-----------------------------------------------------------------------------
|
| 528 |
|
| 529 | #pragma warning(disable : 4100)
|
| 530 | #pragma warning(disable : 4702)
|
| 531 |
|
| 532 | int main ( int argc, char ** argv )
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 533 | {
|
| 534 | SetProcessAffinityMask(GetCurrentProcess(),2);
|
| 535 |
|
| 536 | int a = clock();
|
| 537 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 538 | g_testAll = true;
|
| 539 |
|
| 540 | //g_testWindow = true;
|
| 541 | //g_testSanity = true;
|
| 542 | //g_testSpeed = true;
|
| 543 | //g_testAvalanche = true;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 544 | //g_testCyclic = true;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 545 | //g_testDiff = true;
|
| 546 | //g_testSparse = true;
|
| 547 | //g_testPermutation = true;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 548 | //g_testZeroes = true;
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 549 |
|
| 550 | //testHash("rand32");
|
| 551 | //testHash("rand64");
|
| 552 | //testHash("rand128");
|
| 553 |
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 554 | //testHash("donothing");
|
| 555 |
|
| 556 | //testHash("count");
|
| 557 |
|
| 558 | //printf("Called the hash function %I64d times, %I64d bytes hashed\n",g_hashcount,g_bytecount);
|
| 559 |
|
| 560 | //testHash("crc32");
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 561 | //testHash("rand128");
|
tanjent@gmail.com | 31a9e8e | 2010-11-09 20:29:19 +0000 | [diff] [blame] | 562 |
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 563 | //testHash("fnv");
|
| 564 | //testHash("superfast");
|
| 565 | //testHash("lookup3");
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 566 | //testHash("MurmurOAAT");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 567 |
|
| 568 | //testHash("murmur2");
|
| 569 | //testHash("murmur2B");
|
| 570 | //testHash("murmur2C");
|
| 571 |
|
tanjent@gmail.com | 1d160f0 | 2011-02-28 06:06:41 +0000 | [diff] [blame^] | 572 | testHash("murmur3a");
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 573 | //testHash("murmur3b");
|
| 574 | //testHash("murmur3c");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 575 |
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 576 | //testHash("murmur3d");
|
| 577 | //testHash("murmur3e");
|
| 578 | //testHash("murmur3f");
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 579 |
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 580 | //----------
|
| 581 |
|
tanjent@gmail.com | 7e5c363 | 2010-11-02 00:50:04 +0000 | [diff] [blame] | 582 | int b = clock();
|
| 583 |
|
| 584 | printf("time %d\n",b-a);
|
tanjent@gmail.com | ad4b363 | 2010-11-05 01:20:58 +0000 | [diff] [blame] | 585 |
|
| 586 | return 0;
|
tanjent@gmail.com | babb553 | 2011-02-28 06:03:12 +0000 | [diff] [blame] | 587 | } |