-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hashmap.c
67 lines (54 loc) · 1.52 KB
/
test_hashmap.c
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
#define DEBUG
#include "hashmap.h"
#include "stdlib.h"
#include "assert.h"
int main() {
bool ret;
u64 test_size = 1000000;
char **keys = malloc(sizeof(char *) * test_size);
char **data = malloc(sizeof(char *) * test_size);
for (u64 i = 0; i < test_size; i++) {
char *key = malloc(sizeof(char) * 16);
char *datum = malloc(sizeof(char) * 16);
sprintf(key, "toast-%llu", i);
sprintf(datum, "floopy-%llu", i);
keys[i] = key;
data[i] = datum;
}
printf("Built dataset!\n");
HashMap *map = hm_sized_init(test_size * 2);
for (u64 i = 0; i < 5; i++) {
char *key = keys[i];
hm_insert(&map, key, (void *)"floopy");
hm_insert(&map, key, (void *)"floopy");
ret = hm_remove(map, key);
assert(ret == true);
ret = hm_remove(map, key);
assert(ret == false);
}
printf("Finished quick check\n");
u64 start = get_time_ms();
for (u64 i = 0; i < test_size; i++) {
char *key = keys[i];
char *datum = data[i];
hm_insert(&map, key, (void *)datum);
}
printf("Allocation took: %llu ms\n", get_time_ms() - start);
start = get_time_ms();
for (u64 i = 0; i < test_size; i++) {
char *key = keys[i];
char *result = (char *)hm_get(map, key);
assert(result != NULL);
assert(result[0] == 'f');
}
printf("Indexing took: %llu ms\n", get_time_ms() - start);
start = get_time_ms();
for (u64 i = 0; i < test_size; i++) {
char *key = keys[i];
ret = hm_remove(map, key);
assert(ret == true);
}
printf("Removal took: %llu ms\n", get_time_ms() - start);
assert(!map->idx_map_size && !map->size);
hm_free(map);
}