/* * Checking the correctness of str_len() and hash_*() and proving, that * it is faster than the classical version ;-) */ #include #include #include #include #include /* It will be divided by (10 + strlen()). */ #define TEST_TIME 1000000 /* The shift of the string according to the alignment. */ static uint alignment = 0; static void random_string(byte *str, int len) { int i; for (i=0; i 1) alignment = atoi(argv[1]); printf("Alignment set to %d\n", alignment); for (i=0; strings[i]; i++) if (strlen(strings[i]) != str_len(strings[i])) die("Internal str_len() error on string %d", i); printf("%d strings tested OK\n", i); for (i=0; strings[i]; i++) { uint h1, h2; h1 = hash_string(strings[i]); h2 = hash_string_nocase(strings[i]); if (h1 != hash_block(strings[i], str_len(strings[i]))) die("Internal hash_string() error on string %d", i); printf("hash %2d = %08x %08x", i, h1, h2); if (h1 == h2) printf(" upper case?"); printf("\n"); } for (i=0; lengths[i] >= 0; i++) { byte str[lengths[i] + 1 + alignment]; uint count = TEST_TIME / (lengths[i] + 10); uint el1 = 0, el2 = 0, elh = 0, elhn = 0; uint tot1 = 0, tot2 = 0, hash = 0, hashn = 0; uint j; for (j=0; j%d\n", i, i*3-2, i*i, hash_modify(4587, i*3-2, i*i)); printf("test1: %d\n", hash_modify(lengths[5], 345, i)); */ return 0; }