Internal test cleanup

PiperOrigin-RevId: 339287832
This commit is contained in:
leveldb Team 2020-10-27 11:09:49 -07:00 committed by Chris Mumford
parent b7d3023269
commit ed781070b4

View File

@ -7,6 +7,7 @@
#include <atomic> #include <atomic>
#include <string> #include <string>
#include "testing/base/public/benchmark.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "db/db_impl.h" #include "db/db_impl.h"
#include "db/filename.h" #include "db/filename.h"
@ -2238,7 +2239,9 @@ std::string MakeKey(unsigned int num) {
return std::string(buf); 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"; std::string dbname = testing::TempDir() + "leveldb_test_benchmark";
DestroyDB(dbname, Options()); DestroyDB(dbname, Options());
@ -2273,7 +2276,7 @@ void BM_LogAndApply(int iters, int num_base_files) {
uint64_t start_micros = env->NowMicros(); uint64_t start_micros = env->NowMicros();
for (int i = 0; i < iters; i++) { for (auto st : state) {
VersionEdit vedit; VersionEdit vedit;
vedit.RemoveFile(2, fnum); vedit.RemoveFile(2, fnum);
InternalKey start(MakeKey(2 * fnum), 1, kTypeValue); InternalKey start(MakeKey(2 * fnum), 1, kTypeValue);
@ -2286,21 +2289,15 @@ void BM_LogAndApply(int iters, int num_base_files) {
char buf[16]; char buf[16];
std::snprintf(buf, sizeof(buf), "%d", num_base_files); std::snprintf(buf, sizeof(buf), "%d", num_base_files);
std::fprintf(stderr, std::fprintf(stderr,
"BM_LogAndApply/%-6s %8d iters : %9u us (%7.0f us / iter)\n", "BM_LogAndApply/%-6s %8zu iters : %9u us (%7.0f us / iter)\n",
buf, iters, us, ((float)us) / iters); buf, state.iterations(), us, ((float)us) / state.iterations());
} }
BENCHMARK(BM_LogAndApply)->Arg(1)->Arg(100)->Arg(10000)->Arg(100000);
} // namespace leveldb } // namespace leveldb
int main(int argc, char** argv) { 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); testing::InitGoogleTest(&argc, argv);
RunSpecifiedBenchmarks();
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }