-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmarks.cpp
133 lines (105 loc) · 3.67 KB
/
benchmarks.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
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
132
133
//
// Created by nbdy on 01.11.21.
//
#include "test_common.h"
void benchmarkSingleInsert(const char* name, uint32_t count) {
Database db(TEST_DB_PATH);
TIMEIT_START(name)
insertEntryOneSingle(&db, count);
TIMEIT_END
TIMEIT_RESULT
EXPECT_EQ(db.getEntryCount(), count);
std::cout << db.getFileSize() << std::endl;
EXPECT_TRUE(deleteDatabase(&db));
}
void benchmarkMultipleInsert(const char* name, uint32_t count, uint32_t chunkSize) {
Database db(TEST_DB_PATH);
TIMEIT_START(name)
insertEntryOneMultiple(&db, count, chunkSize);
TIMEIT_END
TIMEIT_RESULT
EXPECT_EQ(db.getEntryCount(), count);
std::cout << db.getFileSize() << std::endl;
EXPECT_TRUE(deleteDatabase(&db));
}
TEST(Database, benchmark1kInsert) {
static uint32_t chunkSize = 10;
static uint32_t count = 1000;
benchmarkSingleInsert("benchmark1kSingleInsert", count);
benchmarkMultipleInsert("benchmark1kMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark10kChunkSize10Insert) {
static uint32_t chunkSize = 10;
static uint32_t count = 10000;
benchmarkSingleInsert("benchmark10kSingleInsert", count);
benchmarkMultipleInsert("benchmark10kMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark100kChunkSize10Insert) {
static uint32_t count = 100000;
static uint32_t chunkSize = 10;
benchmarkSingleInsert("benchmark100kSingleInsert", count);
benchmarkMultipleInsert("benchmark100kMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark1mChunkSize10Insert) {
static uint32_t count = 1000000;
static uint32_t chunkSize = 10;
benchmarkMultipleInsert("benchmark1mMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark10kChunkSize100Insert) {
static uint32_t count = 10000;
static uint32_t chunkSize = 100;
benchmarkMultipleInsert("benchmark10kMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark100kChunkSize100Insert) {
static uint32_t count = 100000;
static uint32_t chunkSize = 100;
benchmarkMultipleInsert("benchmark100kMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark1mChunkSize100Insert) {
static uint32_t count = 1000000;
static uint32_t chunkSize = 100;
benchmarkMultipleInsert("benchmark1mMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark10kChunkSize1kInsert) {
static uint32_t count = 10000;
static uint32_t chunkSize = 1000;
benchmarkMultipleInsert("benchmark10kMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark100kChunkSize1kInsert) {
static uint32_t count = 100000;
static uint32_t chunkSize = 1000;
benchmarkMultipleInsert("benchmark100kMultipleInsert", count, chunkSize);
}
TEST(Database, benchmark1mChunkSize1kInsert) {
static uint32_t count = 1000000;
static uint32_t chunkSize = 1000;
benchmarkMultipleInsert("benchmark1mMultipleInsert", count, chunkSize);
}
void benchmarkSearch(const char* name, uint32_t count) {
Database db(TEST_DB_PATH);
uint32_t ic = count / 4;
insertEntryTwoMultiple(&db, ic - 1, 1000);
insertEntryOneMultiple(&db, ic, 1000);
insertEntryThreeMultiple(&db, ic, 1000);
db.insert(EntryThree { 4.44, "AYOOO this is the right entry"});
insertEntryTwoMultiple(&db, ic, 1000);
EntryThree e {};
TIMEIT_START(name)
auto idx = db.find<EntryThree>(e, [](const EntryThree& entry) {
return entry.m_Double == 4.44;
});
TIMEIT_END
TIMEIT_RESULT
EXPECT_NE(idx, -1);
EXPECT_TRUE(strcmp(e.m_String, "AYOOO this is the right entry") == 0);
EXPECT_TRUE(deleteDatabase(&db));
}
TEST(Database, benchmark10kSearch) {
benchmarkSearch("benchmark10kSearch", 10000);
}
TEST(Database, benchmark100kSearch) {
benchmarkSearch("benchmark100kSearch", 100000);
}
TEST(Database, benchmark1mSearch) {
benchmarkSearch("benchmark1mSearch", 1000000);
}