Skip to content

Commit

Permalink
Refactored benchmark code;
Browse files Browse the repository at this point in the history
  • Loading branch information
zethon committed May 30, 2021
1 parent dbd2053 commit babe67e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,28 @@ The database options can be configured through the `Options` struct located in `
`
## Performance

This project is in early development so that the primary goal is to get basic functionality complete before optimizing for performance. This does not mean that performance is being ignored but it does mean that the path of least development will be favored for the near future.
Though there are still some planned public API calls to be implemented, the primary _vision_ for the API is complete. Pre-release development focused on the initial implementation, with future releases planned to focus on performance.

```
Run on (16 X 2300 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x8)
L1 Instruction 32 KiB (x8)
L2 Unified 256 KiB (x8)
L3 Unified 16384 KiB (x1)
Load Average: 2.11, 2.01, 1.79
--------------------------------------------------------------------
Benchmark Time CPU Iterations
--------------------------------------------------------------------
BM_DBCreateOpen 25794 ns 25792 ns 26568
BM_DBOpenClose 25181 ns 25181 ns 27629
BM_DBWriteInt 91354 ns 91269 ns 7487
BM_DBMultipleIntWrites 9255495 ns 9255213 ns 75
BM_DBRandomIntReads 1845182 ns 1846939 ns 378
BM_DBWriteStruct 97525 ns 95837 ns 7297
BM_DBMultipleStructWrites 10170736 ns 10177726 ns 73
BM_DBRandomStructReads 1975045 ns 1977746 ns 354
```

## Repository Contents

Expand Down
23 changes: 15 additions & 8 deletions benchmarks/bench_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void BM_DBCreateOpen(benchmark::State& state)
options.create_if_missing = true;
options.error_if_exists = false;

for (auto _ : state)
while (state.KeepRunning())
{
StringDB db{ tempfolder, options };
db.open();
Expand All @@ -40,7 +40,7 @@ static void BM_DBOpenClose(benchmark::State& state)

StringDB db{ tempfolder, options };

for (auto _ : state)
while (state.KeepRunning())
{
db.open();
db.close();
Expand All @@ -58,7 +58,7 @@ static void BM_DBWriteInt(benchmark::State& state)
ashdb::AshDB<int> db{ tempfolder, options };
db.open();

for (auto _ : state)
while (state.KeepRunning())
{
db.write(3);
}
Expand All @@ -75,7 +75,7 @@ static void BM_DBMultipleIntWrites(benchmark::State& state)
ashdb::AshDB<int> db{ tempfolder, options };
db.open();

for (auto _ : state)
while (state.KeepRunning())
{
for (auto i = 0u; i < 100u; ++i)
{
Expand Down Expand Up @@ -103,12 +103,14 @@ static void BM_DBRandomIntReads(benchmark::State& state)
db.write(3);
}

for (auto _ : state)
while (state.KeepRunning())
{
for (auto i = 0u; i < 100u; ++i)
{
state.PauseTiming();
std::uniform_int_distribution<> distrib(0, 99);
std::uint32_t xi = static_cast<std::uint32_t>(distrib(gen));
state.ResumeTiming();
db.read(xi);
}
}
Expand Down Expand Up @@ -136,7 +138,7 @@ static void BM_DBWriteStruct(benchmark::State& state)
p.salary = 12345.67;
p.married = true;

for (auto _ : state)
while (state.KeepRunning())
{
db.write(p);
}
Expand All @@ -154,17 +156,19 @@ static void BM_DBMultipleStructWrites(benchmark::State& state)
ashdb::AshDB<project::Person> db{ tempfolder, options };
db.open();

for (auto _ : state)
while (state.KeepRunning())
{
for (auto i = 0u; i < 100; ++i)
{
state.PauseTiming();
project::Person p;
p.name.first = "Firstname" + std::to_string(i);
p.name.middle = (i % 2) ? "Middle" + std::to_string(i) : "";
p.name.last = "Lastname" + std::to_string(i);
p.age = (i % 80);
p.salary = (i % 5) * 12345.67;
p.married = (i % 2) == 0;
state.ResumeTiming();

db.write(p);
}
Expand Down Expand Up @@ -198,12 +202,15 @@ static void BM_DBRandomStructReads(benchmark::State& state)
db.write(p);
}

for (auto _ : state)
while (state.KeepRunning())
{
for (auto i = 0u; i < 100u; ++i)
{
state.PauseTiming();
std::uniform_int_distribution<> distrib(0, 99);
std::uint32_t xi = static_cast<std::uint32_t>(distrib(gen));
state.ResumeTiming();

db.read(xi);
}
}
Expand Down

0 comments on commit babe67e

Please sign in to comment.