-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
87 lines (65 loc) · 1.97 KB
/
main.cpp
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
#include <ctime>
#include <iostream>
using std::cout;
using std::endl;
#include "database.h"
double getCurrentTime() {
struct timespec sp;
clock_gettime(CLOCK_REALTIME, &sp);
return (double)sp.tv_sec + (double)sp.tv_nsec / 1000000000.0;
}
void insert_test(Database* db) {
char name[14];
char value[14];
double total_time, start_time;
total_time = 0;
for(unsigned int i = 0; i < 1000000; ++i) {
sprintf(name, "nkey_%u", i);
sprintf(value, "value_%u", i);
start_time = getCurrentTime();
db->set(string(name), string(value));
total_time += getCurrentTime() - start_time;
}
cout << "Insert test: Took " << total_time << " seconds" << endl;
}
void read_test(Database* db) {
char name[20];
char exp_value[20];
string value;
double total_time, start_time;
total_time = 0;
for(unsigned int i = 0; i < 1000000; ++i) {
sprintf(name, "nkey_%u", i);
sprintf(exp_value, "value_%u", i);
start_time = getCurrentTime();
value = db->get(string(name));
if(value.compare(exp_value) != 0) {
cout << "Value different! Is " << value << ", expected " << exp_value << endl;
}
total_time += getCurrentTime() - start_time;
}
cout << "Read test: Took " << total_time << " seconds" << endl;
}
bool filterfunc(string key, string value) {
return (key.find("_123") != string::npos);
}
void filter_test(Database* db) {
double total_time, start_time = getCurrentTime();
list<std::pair<string, string> > results = db->filter(filterfunc);
//list<std::pair<string, string> >::iterator it = results.begin();
total_time = getCurrentTime() - start_time;
/*for(; it != results.end(); ++it) {
cout << it->first << endl;
}*/
cout << results.size() << endl;
cout << "Filter test: Took " << total_time << " seconds" << endl;
}
int main(int argc, char **argv) {
Database db;
db.open("teste");
//insert_test(&db);
//read_test(&db);
filter_test(&db);
db.close();
return 0;
}