X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fstr-test.c;h=48d246fbf943e3fefc88506167c58826232c1313;hb=2771551e0dbfc9517ca6fd68f0db362434ceddbb;hp=adac0fb81d8660409d16eb863a7025c94b51ef41;hpb=045b70ff20b5428965687e0fb16de5c3fea21a55;p=libucw.git diff --git a/lib/str-test.c b/lib/str-test.c index adac0fb8..48d246fb 100644 --- a/lib/str-test.c +++ b/lib/str-test.c @@ -1,9 +1,9 @@ /* - * Checking the correctness of str_len() and str_hash() and proving, that + * Checking the correctness of str_len() and hash_*() and proving, that * it is faster than the classical version ;-) */ -#include "lib/str_hash.h" +#include "lib/hashfunc.h" #include #include @@ -13,8 +13,11 @@ /* It will be divided by (10 + strlen()). */ #define TEST_TIME 1000000 +/* The shift of the string according to the alignment. */ +static uns alignment = 0; + static void -random_string(char *str, int len) +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 error on string %d", i); + die("Internal str_len() error on string %d", i); printf("%d strings tested OK\n", i); for (i=0; strings[i]; i++) - printf("hash %2d = %08x\n", i, str_hash(strings[i])); + { + uns 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++) { - char str[lengths[i] + 1]; + byte str[lengths[i] + 1 + alignment]; uns count = TEST_TIME / (lengths[i] + 10); - uns el1 = 0, el2 = 0, elh = 0; - uns tot1 = 0, tot2 = 0, hash = 0; + uns el1 = 0, el2 = 0, elh = 0, elhn = 0; + uns tot1 = 0, tot2 = 0, hash = 0, hashn = 0; uns j; for (j=0; j