-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathperf_test.c
More file actions
114 lines (106 loc) · 2.13 KB
/
Copy pathperf_test.c
File metadata and controls
114 lines (106 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
Measure the generated perfect hash functions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include <errno.h>
#include "perf.h"
#ifdef _INTKEYS
extern uint32_t inthash(const int32_t);
#else
extern uint32_t hash (const char *, size_t);
#endif
#define MAX_LEN 80
int
main (int argc, char *argv[])
{
char *in = argv[1];
char *log = argv[2];
unsigned size;
char buf[MAX_LEN];
FILE *f = fopen (in, "r");
int ret = 0;
unsigned i = 0, j = 0;
bool isword = strstr(in, "int") ? false : true;
sscanf(argv[3], "%u", &size);
#ifdef bdz
char mapfile[80];
assert(strlen(in) < 80);
strncpy(mapfile, in, 79);
strcat(mapfile, ".map");
uint32_t *map;
size_t lines = 1000;
map = calloc (lines, 4);
i = 0;
// read map file for the indices
FILE *m = fopen(mapfile, "r");
if (!m) {
perror("fopen mapfile");
exit(1);
}
errno = 0;
while (1 == fscanf(m, "%u\n", &map[i]) && !errno) {
i++;
if (i >= lines) {
//fprintf(stderr, "more than %lu lines in %s\n", lines, mapfile);
lines *= 2;
map = realloc (map, lines * 4);
}
}
fclose(m);
#endif
uint64_t t = timer_start ();
restart:
j = 0;
while (fgets (buf, MAX_LEN, f))
{
size_t len = strlen (buf);
if (len > 0 && buf[len - 1] == '\n')
buf[--len] = '\0';
uint32_t h =
#ifdef _INTKEYS
inthash (atoi(buf));
#else
hash (buf, len);
#endif
#ifndef bdz
if (h != j)
{
ret = 1;
printf ("NOT in word set %s, hash %u != index %u\n", buf, h, j);
fclose(f);
abort();
}
#else
if (h != map[j])
{
ret = 1;
printf ("NOT in word set %s, hash %u != index %u\n", buf, h, map[j]);
fclose(f);
free (map);
abort();
}
#endif
i++;
j++;
if (i > PERF_LOOP)
break;
}
if (i < PERF_LOOP)
{
rewind (f);
goto restart;
}
t = timer_end () - t;
fclose(f);
f = fopen (log, "a");
fprintf(f, "%20u %20lu\n", size, t / PERF_LOOP);
fclose(f);
#ifdef bdz
free (map);
#endif
return ret;
}