-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
47 lines (44 loc) · 1.28 KB
/
test.c
File metadata and controls
47 lines (44 loc) · 1.28 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
#include <stdlib.h>
#include <time.h>
#include "hash_table.h"
#define ITERS 10000000ul
// Performance test hash table implementations
int main(void) {
unsigned long micros = 0;
float millis = 0.0;
clock_t start, end;
hash_table_t* ht = ht_create();
int i;
printf("RAND_MAX %d\n", RAND_MAX);
printf("Starting insertions\n");
start = clock();
for (i = 0; i < ITERS; i++) {
//printf("%d\n", i);
//fflush(stdout);
key_t key = rand();
value_t value = rand();
hash_item_t item = { .key = key, .value = value };
ht_insert(ht, item);
}
end = clock();
micros = end - start;
millis = micros / 1000;
printf("Took %fms to perform %lu iterations\n", millis, ITERS);
int successful_lookups = 0;
printf("Starting lookups\n");
start = clock();
for (i = 0; i < ITERS; i++) {
key_t key = rand();
value_t value = ht_lookup(ht, key);
if (value != EMPTY) {
printf("{%lu, %lu}\n", key, value);
successful_lookups++;
}
}
end = clock();
micros = end - start;
millis = micros / 1000;
printf("Took %fms to perform %lu lookups\n", millis, ITERS);
printf("Successfully lookuped up %d keys of %lu attempts\n", successful_lookups, ITERS);
return 0;
}