Skip to content

Commit

Permalink
Updated benchmarks and added cli output for documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdy committed Jan 27, 2022
1 parent ab78ddf commit 97e4b7e
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 76 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,33 @@
<br>
`A header only framework for binary file formats`

## benchmarks
## [benchmarks](doc/Benchmarks.md)

### single insert (append EntryType)

| Number | Time (s) |
|--------|----------|
| 1k | ~ 1 |
| 10k | ~ 13 |
| 100k | toolong |
| 1k | 1.35 |
| 10k | 12.82 |
| 100k | 128.65 |

### vector insert (append std::vector<EntryType>)

| Number | Time (s) |
|--------|----------|
| 1k | < 0 s |
| 1M | 968ms |
| Number | Time (ms) |
|--------|-----------|
| 1k | 1 |
| 10k | 1 |
| 100k | 6 |
| 1M | 40 |

### read

| Number | Time (s) |
|--------|----------|
| 1M | 87ms |
| 1k | 0ms |
| 10k | 0ms |
| 100k | 0ms |
| 1M | 8ms |

## Minimal example

Expand Down
145 changes: 78 additions & 67 deletions benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,96 @@
#include "FunctionTimer/FunctionTimer.h"
#include "test_common.h"

// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test1kInsert) {
auto t = getRandomTestFile();
std::vector<TestBinaryEntry> entries;
for (uint32_t i = 0; i < 1000; i++) {
entries.push_back(generateRandomTestEntryContainer().entry);
}
FunctionTimer ft(
[&t, entries]() { EXPECT_EQ(t.append(entries), binfmt::ErrorCode::OK); });
std::cout << "1k insert: " << ft.getExecutionTimeMs() << "ms" << std::endl;
EXPECT_EQ(t.getFileSize(),
1000 * sizeof(TestBinaryEntryContainer) + sizeof(TestBinaryHeader));
cleanupTestFile(t);
}

// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test10kInsert) {
auto t = getRandomTestFile();
std::vector<TestBinaryEntry> entries;
for (uint32_t i = 0; i < 10000; i++) {
entries.push_back(generateRandomTestEntryContainer().entry);
}
FunctionTimer ft(
[&t, entries]() { EXPECT_EQ(t.append(entries), binfmt::ErrorCode::OK); });
std::cout << "10k insert: " << ft.getExecutionTimeMs() << "ms" << std::endl;
EXPECT_EQ(t.getFileSize(), 10000 * sizeof(TestBinaryEntryContainer) +
sizeof(TestBinaryHeader));
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> allEntries;
EXPECT_TRUE(t.getAllEntries(allEntries));
for (const auto &entry : allEntries) {
EXPECT_EQ(entry.checksum, TestBinaryEntryContainer(entries[ec]).checksum);
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);
}

// NOLINTNEXTLINE(cert-err58-cpp)
TEST(BinaryFile, test100kInsert) {
void testVectorInsert(uint32_t i_u32Count) {
auto t = getRandomTestFile();
std::vector<TestBinaryEntry> entries;
for (uint32_t i = 0; i < 100000; i++) {
entries.push_back(generateRandomTestEntryContainer().entry);
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 << "100k insert: " << ft.getExecutionTimeMs() << "ms" << std::endl;
EXPECT_EQ(t.getFileSize(), 100000 * sizeof(TestBinaryEntryContainer) +
sizeof(TestBinaryHeader));

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, test1MInsert) {
auto t = getRandomTestFile();
std::vector<TestBinaryEntry> entries;
uint32_t insertCount = 10000000;
std::cout << "Generating file of size "
<< std::to_string(insertCount * sizeof(TestBinaryEntryContainer) +
sizeof(TestBinaryHeader))
<< std::endl;
for (uint32_t i = 0; i < insertCount; i++) {
entries.push_back(generateRandomTestEntryContainer().entry);
}
FunctionTimer ft(
[&t, entries]() { EXPECT_EQ(t.append(entries), binfmt::ErrorCode::OK); });
std::cout << "1M insert: " << ft.getExecutionTimeMs() << "ms" << std::endl;
EXPECT_EQ(t.getFileSize(), insertCount * sizeof(TestBinaryEntryContainer) +
sizeof(TestBinaryHeader));
int ec = 0;
std::vector<TestBinaryEntryContainer> allEntries;
FunctionTimer ft1(
[&t, &allEntries]() { EXPECT_TRUE(t.getAllEntries(allEntries)); });
std::cout << "1M getAllEntries: " << ft1.getExecutionTimeMs() << "ms"
<< std::endl;
TEST(BinaryFile, test1kSingleInsert) {
testSingleInsert(1000);
}

for (const auto &entry : allEntries) {
EXPECT_EQ(entry.checksum, TestBinaryEntryContainer(entries[ec]).checksum);
ec++;
}
// cleanupTestFile(t);
// 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);
}
48 changes: 48 additions & 0 deletions doc/Benchmarks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Ryzen 9 3900xt

```
[==========] Running 7 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 7 tests from BinaryFile
[ RUN ] BinaryFile.test1kSingleInsert
Single insert of 1000 items took 1354ms
Size: 8020
1000 getAllEntries: 0ms
[ OK ] BinaryFile.test1kSingleInsert (1366 ms)
[ RUN ] BinaryFile.test10kSingleInsert
Single insert of 10000 items took 12817ms
Size: 80020
10000 getAllEntries: 0ms
[ OK ] BinaryFile.test10kSingleInsert (12820 ms)
[ RUN ] BinaryFile.test100kSingleInsert
Single insert of 100000 items took 128647ms
Size: 800020
100000 getAllEntries: 1ms
[ OK ] BinaryFile.test100kSingleInsert (128656 ms)
[ RUN ] BinaryFile.test1kVectorInsert
Vector insert of 1000 items took 1ms
Size: 8020
1000 getAllEntries: 0ms
[ OK ] BinaryFile.test1kVectorInsert (5 ms)
[ RUN ] BinaryFile.test10kVectorInsert
Vector insert of 10000 items took 1ms
Size: 80020
10000 getAllEntries: 0ms
[ OK ] BinaryFile.test10kVectorInsert (5 ms)
[ RUN ] BinaryFile.test100kVectorInsert
Vector insert of 100000 items took 6ms
Size: 800020
100000 getAllEntries: 0ms
[ OK ] BinaryFile.test100kVectorInsert (19 ms)
[ RUN ] BinaryFile.test1MVectorInsert
Vector insert of 1000000 items took 40ms
Size: 8000020
1000000 getAllEntries: 8ms
[ OK ] BinaryFile.test1MVectorInsert (153 ms)
[----------] 7 tests from BinaryFile (143024 ms total)
[----------] Global test environment tear-down
[==========] 7 tests from 1 test suite ran. (143024 ms total)
[ PASSED ] 7 tests.
```

0 comments on commit 97e4b7e

Please sign in to comment.