-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathtable_test.c
131 lines (126 loc) · 3.29 KB
/
table_test.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (c) 2014 Wu, Xingbo <wuxb45@gmail.com>
*
* All rights reserved. No warranty, explicit or implicit, provided.
*/
#define _GNU_SOURCE
#define _LARGEFILE64_SOURCE
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <execinfo.h>
#include <unistd.h>
#include <string.h>
#include <openssl/sha.h>
#include <inttypes.h>
#include "debug.h"
#include "table.h"
#include "generator.h"
#include "stat.h"
static void
table_test(const uint64_t max_value_size)
{
srandom(debug_time_usec());
const double t0 = debug_time_sec();
uint8_t key[64] __attribute__((aligned(8)));
uint8_t hash[HASHBYTES] __attribute__((aligned(8)));
uint8_t value[1024] __attribute__((aligned(8)));
bzero(value, 1024);
struct Table * const table = table_alloc_default(1.5);
struct GenInfo * const gi = generator_new_uniform(1, max_value_size);
struct KeyValue kv;
kv.klen = 16;
kv.pk = key;
kv.pv = value;
uint64_t count = 0;
while (true) {
sprintf((char *)key, "%016lx", count);
kv.vlen = gi->next(gi);
const bool ri = table_insert_kv_safe(table, &kv);
if (ri == false) {
break;
}
count++;
}
free(gi);
mempool_show(table->mempool);
//table_show(table, stdout);
const double t1 = debug_time_sec();
uint64_t found1 = 0;
for (uint64_t i = 0; i < count; i++) {
sprintf((char *)key, "%016lx", i);
SHA1(key, 16, hash);
struct KeyValue * const kv = table_lookup(table, 16, key, hash);
if (kv) {
found1++;
free(kv);
}
}
const double t2 = debug_time_sec();
{
const bool rbt = table_build_bloomtable(table);
assert(rbt == true);
const bool rre = table_retain(table);
assert(rre == true);
}
//table_show(table, stdout);
const double t3 = debug_time_sec();
{
const int fd_out = open("/tmp/raw", O_CREAT | O_WRONLY | O_LARGEFILE, 00666);
const uint64_t nr_dump = table_dump_barrels(table, fd_out, 0);
assert(nr_dump == count);
close(fd_out);
}
const bool rdm = table_dump_meta(table, "/tmp/meta", 0);
const double t4 = debug_time_sec();
//metatable
assert(rdm);
const int fd_in = open("/tmp/raw", O_RDONLY | O_LARGEFILE, 00666);
struct Stat stat;
bzero(&stat, sizeof(stat));
struct MetaTable * const mt = metatable_load("/tmp/meta", fd_in, true, &stat);
assert(mt);
const double t5 = debug_time_sec();
uint64_t found2 = 0;
for (uint64_t i = 0; i < count; i++) {
sprintf((char *)key, "%016lx", i);
SHA1(key, 16, hash);
struct KeyValue * const kv = metatable_lookup(mt, 16, key, hash);
if (kv) {
found2++;
free(kv);
}
}
const double t6 = debug_time_sec();
stat_show(&stat, stdout);
table_analysis_verbose(table, stdout);
char buffer[1024];
table_analysis_short(table, buffer);
fprintf(stdout, "%s\n", buffer);
printf("insert %lf\n", t1-t0);
printf("lookup %lf\n", t2-t1);
printf("retain %lf\n", t3-t2);
printf("dump %lf\n", t4-t3);
printf("load %lf\n", t5-t4);
printf("lookup %lf\n", t6-t5);
table_free(table);
metatable_free(mt);
}
int
main(int argc, char ** argv)
{
(void)argc;
(void)argv;
table_test(200);
table_test(300);
table_test(400);
table_test(500);
table_test(600);
return 0;
}