Skip to content

Commit

Permalink
Internal test cleanup
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 339287832
  • Loading branch information
leveldb Team authored and cmumford committed Nov 30, 2020
1 parent b7d3023 commit ed78107
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <atomic>
#include <string>

#include "testing/base/public/benchmark.h"
#include "gtest/gtest.h"
#include "db/db_impl.h"
#include "db/filename.h"
Expand Down Expand Up @@ -2238,7 +2239,9 @@ std::string MakeKey(unsigned int num) {
return std::string(buf);
}

void BM_LogAndApply(int iters, int num_base_files) {
static void BM_LogAndApply(benchmark::State& state) {
const int num_base_files = state.range(0);

std::string dbname = testing::TempDir() + "leveldb_test_benchmark";
DestroyDB(dbname, Options());

Expand Down Expand Up @@ -2273,7 +2276,7 @@ void BM_LogAndApply(int iters, int num_base_files) {

uint64_t start_micros = env->NowMicros();

for (int i = 0; i < iters; i++) {
for (auto st : state) {
VersionEdit vedit;
vedit.RemoveFile(2, fnum);
InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
Expand All @@ -2286,21 +2289,15 @@ void BM_LogAndApply(int iters, int num_base_files) {
char buf[16];
std::snprintf(buf, sizeof(buf), "%d", num_base_files);
std::fprintf(stderr,
"BM_LogAndApply/%-6s %8d iters : %9u us (%7.0f us / iter)\n",
buf, iters, us, ((float)us) / iters);
"BM_LogAndApply/%-6s %8zu iters : %9u us (%7.0f us / iter)\n",
buf, state.iterations(), us, ((float)us) / state.iterations());
}

BENCHMARK(BM_LogAndApply)->Arg(1)->Arg(100)->Arg(10000)->Arg(100000);
} // namespace leveldb

int main(int argc, char** argv) {
if (argc > 1 && std::string(argv[1]) == "--benchmark") {
leveldb::BM_LogAndApply(1000, 1);
leveldb::BM_LogAndApply(1000, 100);
leveldb::BM_LogAndApply(1000, 10000);
leveldb::BM_LogAndApply(100, 100000);
return 0;
}

testing::InitGoogleTest(&argc, argv);
RunSpecifiedBenchmarks();
return RUN_ALL_TESTS();
}

0 comments on commit ed78107

Please sign in to comment.