-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmarks.cpp
100 lines (79 loc) · 2.82 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
//
// Created by nbdy on 02.09.21.
//
#include "FunctionTimer/FunctionTimer.h"
#include "test_common.h"
template<typename FileType>
void benchmark_read(FileType* i_pFile, uint32_t i_u32Count, std::vector<TestBinaryEntryContainer> entries) {
auto t = *i_pFile;
int ec = 0;
std::vector<TestBinaryEntryContainer> allContainers;
FunctionTimer ft1(
[&t, &allContainers]() { EXPECT_TRUE(t.getAllEntries(allContainers)); });
std::cout << i_u32Count << " getAllEntries: " << ft1.getExecutionTimeMs() << "ms"
<< std::endl;
for (const auto &container : allContainers) {
EXPECT_EQ(container.checksum, TestBinaryEntryContainer(entries[ec]).checksum);
ec++;
}
}
void testSingleInsert(uint32_t i_u32Count) {
auto t = getRandomTestFile();
std::vector<TestBinaryEntryContainer> entries;
FunctionTimer ft([&t, &entries, i_u32Count]() {
for (uint32_t i = 0; i < i_u32Count; i++) {
auto container = generateRandomTestEntryContainer();
entries.emplace_back(container);
EXPECT_EQ(t.append(container.entry),
binfmt::ErrorCode::OK);
}
});
std::cout << "Single insert of " << i_u32Count << " items took " << ft.getExecutionTimeMs() << "ms" << std::endl;
EXPECT_EQ(t.getFileSize(), i_u32Count * sizeof(TestBinaryEntryContainer) + sizeof(TestBinaryHeader));
std::cout << "Size: " << t.getFileSize() << std::endl;
benchmark_read(&t, i_u32Count, entries);
cleanupTestFile(t);
}
void testVectorInsert(uint32_t i_u32Count) {
auto t = getRandomTestFile();
std::vector<TestBinaryEntryContainer> entries;
for (uint32_t i = 0; i < i_u32Count; i++) {
entries.push_back(generateRandomTestEntryContainer());
}
FunctionTimer ft([&t, &entries]() {
EXPECT_EQ(t.append(entries), binfmt::ErrorCode::OK);
});
std::cout << "Vector insert of " << i_u32Count << " items took " << ft.getExecutionTimeMs() << "ms" << std::endl;
EXPECT_EQ(t.getFileSize(), i_u32Count * sizeof(TestBinaryEntryContainer) + sizeof(TestBinaryHeader));
std::cout << "Size: " << t.getFileSize() << std::endl;
benchmark_read(&t, i_u32Count, entries);
cleanupTestFile(t);
}
// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test1kSingleInsert) {
testSingleInsert(1000);
}
// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test10kSingleInsert) {
testSingleInsert(10000);
}
// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test100kSingleInsert) {
testSingleInsert(100000);
}
// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test1kVectorInsert) {
testVectorInsert(1000);
}
// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test10kVectorInsert) {
testVectorInsert(10000);
}
// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test100kVectorInsert) {
testVectorInsert(100000);
}
// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test1MVectorInsert) {
testVectorInsert(1000000);
}