Annotation of libaitcrc/example/test_hash.c, revision 1.2.6.3
1.2 misho 1: #include <stdio.h>
2: #include <string.h>
3: #include <fcntl.h>
4: #include <unistd.h>
1.2.6.1 misho 5: #include <sys/types.h>
6: #include <sys/endian.h>
7: #include <sys/time.h>
1.2 misho 8: #include "aitcrc.h"
9:
10:
11: int main()
12: {
13: int i, f;
1.2.6.1 misho 14: u_int n;
1.2 misho 15: char szLine[256], szAvalanche[][2] = { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 },
16: { 4, 0 }, { 5, 0 }, { 6, 0 }, { 7, 0 } };
17: struct timeval before, after;
18:
19: f = open("/dev/urandom", O_RDONLY);
20: if (f == -1)
21: return 1;
22: // hash_varchar
23: gettimeofday(&before, NULL);
1.2.6.1 misho 24: for (i = 0; i < 100000; i++) {
1.2 misho 25: memset(szLine, 0, 256);
26: read(f, szLine, 255);
1.2.6.1 misho 27: hash_varchar(szLine, 256, 1);
1.2 misho 28: // printf("%u\n", hash_varchar(szLine, 256));
29: }
30: gettimeofday(&after, NULL);
31: printf("hash_varchar:: elapsed time %f seconds\n",
32: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
33: // hash_bernstein
34: gettimeofday(&before, NULL);
1.2.6.1 misho 35: for (i = 0; i < 100000; i++) {
1.2 misho 36: memset(szLine, 0, 256);
37: read(f, szLine, 255);
38: hash_bernstein(szLine, 256, 0);
39: // printf("%u\n", hash_varchar(szLine, 256));
40: }
41: gettimeofday(&after, NULL);
42: printf("hash_bernstein:: elapsed time %f seconds\n",
43: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
44: // hash_bernstein DJBX33A
45: gettimeofday(&before, NULL);
1.2.6.1 misho 46: for (i = 0; i < 100000; i++) {
1.2 misho 47: memset(szLine, 0, 256);
48: read(f, szLine, 255);
49: hash_bernstein(szLine, 256, 1);
50: // printf("%u\n", hash_varchar(szLine, 256));
51: }
52: gettimeofday(&after, NULL);
53: printf("hash_bernstein DJBX33A:: elapsed time %f seconds\n",
54: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
55: // hash_FNV-1a
56: gettimeofday(&before, NULL);
1.2.6.1 misho 57: for (i = 0; i < 100000; i++) {
1.2 misho 58: memset(szLine, 0, 256);
59: read(f, szLine, 255);
60: hash_fnv1(szLine, 256, 0);
61: // printf("%u\n", hash_varchar(szLine, 256));
62: }
63: gettimeofday(&after, NULL);
64: printf("hash_fnv1:: elapsed time %f seconds\n",
65: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
66: // hash_FNV-1
67: gettimeofday(&before, NULL);
1.2.6.1 misho 68: for (i = 0; i < 100000; i++) {
1.2 misho 69: memset(szLine, 0, 256);
70: read(f, szLine, 255);
71: hash_fnv1(szLine, 256, 1);
72: // printf("%u\n", hash_varchar(szLine, 256));
73: }
74: gettimeofday(&after, NULL);
75: printf("hash_fnv1 A:: elapsed time %f seconds\n",
76: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
77: // hash_jenkins
78: gettimeofday(&before, NULL);
1.2.6.1 misho 79: for (i = 0; i < 100000; i++) {
1.2 misho 80: memset(szLine, 0, 256);
81: read(f, szLine, 255);
82: hash_jenkins(szLine, 256);
83: // printf("%u\n", hash_varchar(szLine, 256));
84: }
85: gettimeofday(&after, NULL);
86: printf("hash_jenkins:: elapsed time %f seconds\n",
87: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
88:
1.2.6.1 misho 89: // hash_jenkins32
90: gettimeofday(&before, NULL);
91: for (i = 0; i < 100000; i++) {
92: memset(szLine, 0, 256);
93: read(f, szLine, 255);
1.2.6.3 ! misho 94: /*n =*/ hash_jenkins32((u_int*) szLine, 256 / 4, 0);
! 95: // printf("%u\n", n);
1.2.6.1 misho 96: }
97: gettimeofday(&after, NULL);
98: printf("hash_jenkins32:: elapsed time %f seconds\n",
99: (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1.e6);
100:
1.2 misho 101: close(f);
102: printf("\n");
1.2.6.1 misho 103:
1.2 misho 104: printf("Test avalanche 0 .. 7::\n");
105:
106: printf(" hash_varchar:");
107: for (i = 0; i < 8; i++) {
108: memset(szLine, 0, 256);
109: memcpy(szLine, &szAvalanche[i][0], 1);
110: printf(" %d=>%u", i, hash_varchar(szLine, 1, 1));
111: }
112: printf("\n");
113: printf(" hash_fnv1:");
114: for (i = 0; i < 8; i++) {
115: memset(szLine, 0, 256);
116: memcpy(szLine, &szAvalanche[i][0], 1);
117: printf(" %d=>%u", i, hash_fnv1(szLine, 1, 0));
118: }
119: printf("\n");
120: printf(" hash_fnv1 A:");
121: for (i = 0; i < 8; i++) {
122: memset(szLine, 0, 256);
123: memcpy(szLine, &szAvalanche[i][0], 1);
124: printf(" %d=>%u", i, hash_fnv1(szLine, 1, 1));
125: }
126: printf("\n");
127: printf(" hash_fnv1 A (define):");
128: for (i = 0; i < 8; i++) {
129: memset(szLine, 0, 256);
130: memcpy(szLine, &szAvalanche[i][0], 1);
131: printf(" %d=>%u", i, hash_fnv(szLine, 1));
132: }
133: printf("\n");
134: printf(" hash_bernstein:");
135: for (i = 0; i < 8; i++) {
136: memset(szLine, 0, 256);
137: memcpy(szLine, &szAvalanche[i][0], 1);
138: printf(" %d=>%u", i, hash_bernstein(szLine, 1, 0));
139: }
140: printf("\n");
141: printf(" hash_bernstein DJBX33A:");
142: for (i = 0; i < 8; i++) {
143: memset(szLine, 0, 256);
144: memcpy(szLine, &szAvalanche[i][0], 1);
145: printf(" %d=>%u", i, hash_bernstein(szLine, 1, 1));
146: }
147: printf("\n");
148: printf(" hash_jenkins:");
149: for (i = 0; i < 8; i++) {
150: memset(szLine, 0, 256);
151: memcpy(szLine, &szAvalanche[i][0], 1);
152: printf(" %d=>%u", i, hash_jenkins(szLine, 1));
153: }
154: printf("\n");
1.2.6.1 misho 155: printf(" hash_jenkins32:");
156: for (i = 0; i < 8; i++) {
157: n = szAvalanche[i][0];
1.2.6.2 misho 158: printf(" %d=>%u/", i, hash_jenkins32(&n, 1, 0));
159:
160: memset(szLine, 0, 256);
161: memcpy(szLine, &szAvalanche[i][0], 1);
162: printf("%d=>%u ", i, hash_jenkins32((u_int*) szLine, 1, 0));
1.2.6.1 misho 163: }
164: printf("\n");
1.2 misho 165: printf(" hash_reddragon:");
166: for (i = 0; i < 8; i++) {
167: memset(szLine, 0, 256);
168: memcpy(szLine, &szAvalanche[i][0], 1);
169: printf(" %d=>%u", i, hash_reddragon(szLine, 1));
170: }
171: printf("\n");
172: printf(" aaa>%u\n", hash_reddragon("aaa", 3));
173: printf(" aab>%u\n", hash_reddragon("aab", 3));
174: return 0;
175: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>