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