Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 7 additions & 7 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Language: Cpp
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
Expand Down Expand Up @@ -64,7 +64,7 @@ AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowShortCaseExpressionOnASingleLine: true
Expand Down Expand Up @@ -126,7 +126,7 @@ BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakTemplateDeclarations: Yes
ColumnLimit: 100
ColumnLimit: 120
CommentPragmas: '^\s*(@(addtogroup|copydoc|defgroup|fn|ref)|- )'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
Expand Down Expand Up @@ -190,7 +190,7 @@ JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfFile: true
AtStartOfFile: false
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
Expand All @@ -217,7 +217,7 @@ PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Left
QualifierAlignment: Right
RawStringFormats: []
ReferenceAlignment: Pointer
ReflowComments: true
Expand All @@ -227,7 +227,7 @@ RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
ShortNamespaceLines: 0
SkipMacroDefinitionBody: false
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
Expand Down Expand Up @@ -257,7 +257,7 @@ SpaceBeforeParensOptions:
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 2
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
Expand Down
47 changes: 18 additions & 29 deletions benchmark/benchmark_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,25 @@ namespace benchmark {
// The task sizes and iteration numbers come from the Driver Perfomance Benchmarking Reference Doc.
benchmark_runner::benchmark_runner(std::set<benchmark_type> types) : _types{types} {
// Bson microbenchmarks
_microbenches.push_back(
std::make_unique<bson_encoding>("TestFlatEncoding", 75.31, "extended_bson/flat_bson.json"));
_microbenches.push_back(
std::make_unique<bson_encoding>("TestDeepEncoding", 19.64, "extended_bson/deep_bson.json"));
_microbenches.push_back(
std::make_unique<bson_encoding>("TestFullEncoding", 57.34, "extended_bson/full_bson.json"));
_microbenches.push_back(std::make_unique<bson_encoding>("TestFlatEncoding", 75.31, "extended_bson/flat_bson.json"));
_microbenches.push_back(std::make_unique<bson_encoding>("TestDeepEncoding", 19.64, "extended_bson/deep_bson.json"));
_microbenches.push_back(std::make_unique<bson_encoding>("TestFullEncoding", 57.34, "extended_bson/full_bson.json"));
// TODO CXX-1241: Add bson_decoding equivalents.

// Single doc microbenchmarks
_microbenches.push_back(std::make_unique<run_command>());
_microbenches.push_back(
std::make_unique<find_one_by_id>("single_and_multi_document/tweet.json"));
_microbenches.push_back(std::make_unique<find_one_by_id>("single_and_multi_document/tweet.json"));
_microbenches.push_back(std::make_unique<insert_one>(
"TestSmallDocInsertOne", 2.75, iterations, "single_and_multi_document/small_doc.json"));
_microbenches.push_back(std::make_unique<insert_one>(
"TestLargeDocInsertOne", 27.31, 10, "single_and_multi_document/large_doc.json"));
_microbenches.push_back(
std::make_unique<insert_one>("TestLargeDocInsertOne", 27.31, 10, "single_and_multi_document/large_doc.json"));

// Multi doc microbenchmarks
_microbenches.push_back(std::make_unique<find_many>("single_and_multi_document/tweet.json"));
_microbenches.push_back(std::make_unique<bulk_insert>(
"TestSmallDocBulkInsert", 2.75, iterations, "single_and_multi_document/small_doc.json"));
_microbenches.push_back(std::make_unique<bulk_insert>(
"TestLargeDocBulkInsert", 27.31, 10, "single_and_multi_document/large_doc.json"));
_microbenches.push_back(
std::make_unique<bulk_insert>("TestLargeDocBulkInsert", 27.31, 10, "single_and_multi_document/large_doc.json"));
// CXX-2794: Disable GridFS benchmarks due to long runtime
// _microbenches.push_back(
// std::make_unique<gridfs_upload>("single_and_multi_document/gridfs_large.bin"));
Expand All @@ -86,13 +82,10 @@ benchmark_runner::benchmark_runner(std::set<benchmark_type> types) : _types{type
// Need to remove some
if (!_types.empty()) {
for (auto&& it = _microbenches.begin(); it != _microbenches.end();) {
const std::set<benchmark_type>& tags = (*it)->get_tags();
std::set<benchmark_type> const& tags = (*it)->get_tags();
std::set<benchmark_type> intersect;
std::set_intersection(tags.begin(),
tags.end(),
_types.begin(),
_types.end(),
std::inserter(intersect, intersect.begin()));
std::set_intersection(
tags.begin(), tags.end(), _types.begin(), _types.end(), std::inserter(intersect, intersect.begin()));

if (intersect.empty()) {
_microbenches.erase(it);
Expand All @@ -112,8 +105,7 @@ void benchmark_runner::run_microbenches() {

auto score = bench->get_results();

std::cout << bench->get_name() << ": "
<< static_cast<double>(score.get_percentile(50).count()) / 1000.0
std::cout << bench->get_name() << ": " << static_cast<double>(score.get_percentile(50).count()) / 1000.0
<< " second(s) | " << score.get_score() << " MB/s" << std::endl
<< std::endl;
}
Expand Down Expand Up @@ -168,12 +160,9 @@ void benchmark_runner::write_scores() {
using builder::basic::sub_document;

auto doc = builder::basic::document{};
doc.append(kvp("info", [](sub_document subdoc) {
subdoc.append(kvp("test_name", "C++ Driver microbenchmarks"));
}));
doc.append(kvp("info", [](sub_document subdoc) { subdoc.append(kvp("test_name", "C++ Driver microbenchmarks")); }));

auto write_time =
[](const std::chrono::time_point<std::chrono::system_clock> t) -> std::string {
auto write_time = [](std::chrono::time_point<std::chrono::system_clock> const t) -> std::string {
std::time_t t1 = std::chrono::system_clock::to_time_t(t);
std::ostringstream oss;
oss << std::put_time(std::gmtime(&t1), "%Y-%m-%dT%H:%M:%S") << "+00:00";
Expand All @@ -189,10 +178,10 @@ void benchmark_runner::write_scores() {
std::cout << "Individual microbenchmark scores:" << std::endl << "===========" << std::endl;
for (auto&& bench : _microbenches) {
auto& score = bench->get_results();
const auto bench_time = static_cast<double>(score.get_percentile(50).count()) / 1000.0;
auto const bench_time = static_cast<double>(score.get_percentile(50).count()) / 1000.0;

std::cout << bench->get_name() << ": " << bench_time << " seconds | " << score.get_score()
<< " MB/s" << std::endl;
std::cout << bench->get_name() << ": " << bench_time << " seconds | " << score.get_score() << " MB/s"
<< std::endl;

auto metric_doc = builder::basic::document{};
metric_doc.append(kvp("name", bench->get_name()));
Expand Down Expand Up @@ -232,4 +221,4 @@ void benchmark_runner::write_scores() {
std::ofstream os{"results.json"};
os << '[' << bsoncxx::to_json(doc.view()) << ']';
}
} // namespace benchmark
} // namespace benchmark
2 changes: 1 addition & 1 deletion benchmark/benchmark_runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ class benchmark_runner {
std::vector<std::unique_ptr<microbench>> _microbenches;
std::set<benchmark_type> _types;
};
} // namespace benchmark
} // namespace benchmark
6 changes: 2 additions & 4 deletions benchmark/bson/bson_decoding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class bson_decoding : public microbench {
bson_decoding() = delete;

bson_decoding(std::string name, double task_size, std::string json_file)
: microbench{std::move(name),
task_size,
std::set<benchmark_type>{benchmark_type::bson_bench}},
: microbench{std::move(name), task_size, std::set<benchmark_type>{benchmark_type::bson_bench}},
_file_name{std::move(json_file)} {}

protected:
Expand All @@ -46,4 +44,4 @@ void bson_decoding::task() {
// TODO CXX-1241: call bson_as_extended json on _json.
}
}
} // namespace benchmark
} // namespace benchmark
6 changes: 2 additions & 4 deletions benchmark/bson/bson_encoding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class bson_encoding : public microbench {
bson_encoding() = delete;

bson_encoding(std::string name, double task_size, std::string json_file)
: microbench{std::move(name),
task_size,
std::set<benchmark_type>{benchmark_type::bson_bench}},
: microbench{std::move(name), task_size, std::set<benchmark_type>{benchmark_type::bson_bench}},
_json_file{std::move(json_file)} {}

protected:
Expand Down Expand Up @@ -64,4 +62,4 @@ void bson_encoding::task() {
}

void bson_encoding::teardown() {}
} // namespace benchmark
} // namespace benchmark
2 changes: 1 addition & 1 deletion benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main(int argc, char* argv[]) {

if (argc > 1) {
if (bsoncxx::stdx::string_view(argv[1]) == "all") {
for (const auto& [name, type] : names_types) {
for (auto const& [name, type] : names_types) {
types.insert(type);
}
} else {
Expand Down
12 changes: 5 additions & 7 deletions benchmark/microbench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

namespace benchmark {

bool finished_running(const std::chrono::duration<std::uint32_t, std::milli>& curr_time,
std::uint32_t iter) {
bool finished_running(std::chrono::duration<std::uint32_t, std::milli> const& curr_time, std::uint32_t iter) {
return (curr_time > maxtime || (curr_time > mintime && iter > max_iter));
}

Expand All @@ -44,7 +43,7 @@ void microbench::run() {
teardown();
}

std::vector<std::string> parse_json_file_to_strings(const std::string& json_file) {
std::vector<std::string> parse_json_file_to_strings(std::string const& json_file) {
std::vector<std::string> jsons;
std::ifstream stream{"data/benchmark/" + json_file};

Expand All @@ -60,7 +59,7 @@ std::vector<std::string> parse_json_file_to_strings(const std::string& json_file
return jsons;
}

std::vector<bsoncxx::document::value> parse_json_file_to_documents(const std::string& json_file) {
std::vector<bsoncxx::document::value> parse_json_file_to_documents(std::string const& json_file) {
std::vector<bsoncxx::document::value> docs;
std::ifstream stream{"data/benchmark/" + json_file};

Expand All @@ -79,12 +78,11 @@ std::vector<bsoncxx::document::value> parse_json_file_to_documents(const std::st
return docs;
}

std::vector<std::string> parse_documents_to_bson(
const std::vector<bsoncxx::document::value>& docs) {
std::vector<std::string> parse_documents_to_bson(std::vector<bsoncxx::document::value> const& docs) {
std::vector<std::string> bsons;
for (std::uint32_t i = 0; i < docs.size(); i++) {
bsons.push_back(bsoncxx::to_json(docs[i]));
}
return bsons;
}
} // namespace benchmark
} // namespace benchmark
18 changes: 9 additions & 9 deletions benchmark/microbench.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum class benchmark_type {
run_command_bench,
};

static const std::unordered_map<benchmark_type, std::string> type_names = {
static std::unordered_map<benchmark_type, std::string> const type_names = {
{benchmark_type::bson_bench, "BSONBench"},
{benchmark_type::single_bench, "SingleBench"},
{benchmark_type::multi_bench, "MultiBench"},
Expand All @@ -46,7 +46,7 @@ static const std::unordered_map<benchmark_type, std::string> type_names = {
{benchmark_type::write_bench, "WriteBench"},
{benchmark_type::run_command_bench, "RunCommandBench"}};

static const std::unordered_map<std::string, benchmark_type> names_types = {
static std::unordered_map<std::string, benchmark_type> const names_types = {
{"BSONBench", benchmark_type::bson_bench},
{"SingleBench", benchmark_type::single_bench},
{"MultiBench", benchmark_type::multi_bench},
Expand All @@ -72,8 +72,8 @@ class microbench {

microbench(microbench&&) = default;
microbench& operator=(microbench&&) = default;
microbench(const microbench&) = default;
microbench& operator=(const microbench&) = default;
microbench(microbench const&) = default;
microbench& operator=(microbench const&) = default;

void run();

Expand All @@ -85,7 +85,7 @@ class microbench {
return _score;
}

const std::set<benchmark_type>& get_tags() {
std::set<benchmark_type> const& get_tags() {
return _tags;
}

Expand All @@ -109,9 +109,9 @@ class microbench {
std::string _name;
};

std::vector<std::string> parse_json_file_to_strings(const std::string& json_file);
std::vector<std::string> parse_json_file_to_strings(std::string const& json_file);

std::vector<bsoncxx::document::value> parse_json_file_to_documents(const std::string& json_file);
std::vector<bsoncxx::document::value> parse_json_file_to_documents(std::string const& json_file);

std::vector<std::string> parse_documents_to_bson(const std::vector<bsoncxx::document::value>& docs);
} // namespace benchmark
std::vector<std::string> parse_documents_to_bson(std::vector<bsoncxx::document::value> const& docs);
} // namespace benchmark
7 changes: 2 additions & 5 deletions benchmark/multi_doc/bulk_insert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class bulk_insert : public microbench {
bulk_insert() = delete;

bulk_insert(std::string name, double task_size, std::int32_t doc_num, std::string json_file)
: microbench{std::move(name),
task_size,
std::set<benchmark_type>{benchmark_type::multi_bench,
benchmark_type::write_bench}},
: microbench{std::move(name), task_size, std::set<benchmark_type>{benchmark_type::multi_bench, benchmark_type::write_bench}},
_conn{mongocxx::uri{}},
_doc_num{doc_num},
_file_name{std::move(json_file)} {}
Expand Down Expand Up @@ -85,4 +82,4 @@ void bulk_insert::teardown() {
void bulk_insert::task() {
_coll.insert_many(_docs);
}
} // namespace benchmark
} // namespace benchmark
7 changes: 2 additions & 5 deletions benchmark/multi_doc/find_many.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ class find_many : public microbench {
public:
// The task size comes from the Driver Perfomance Benchmarking Reference Doc.
find_many(std::string json_file)
: microbench{"TestFindManyAndEmptyCursor",
16.22,
std::set<benchmark_type>{benchmark_type::multi_bench,
benchmark_type::read_bench}},
: microbench{"TestFindManyAndEmptyCursor", 16.22, std::set<benchmark_type>{benchmark_type::multi_bench, benchmark_type::read_bench}},
_conn{mongocxx::uri{}},
_json_file{std::move(json_file)} {}

Expand Down Expand Up @@ -74,4 +71,4 @@ void find_many::task() {
for ([[maybe_unused]] auto&& doc : cursor) {
}
}
} // namespace benchmark
} // namespace benchmark
10 changes: 3 additions & 7 deletions benchmark/multi_doc/gridfs_download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ class gridfs_download : public microbench {
public:
// The task size comes from the Driver Perfomance Benchmarking Reference Doc.
gridfs_download(std::string file_name)
: microbench{"TestGridFsDownload",
52.43,
std::set<benchmark_type>{benchmark_type::multi_bench,
benchmark_type::read_bench}},
: microbench{"TestGridFsDownload", 52.43, std::set<benchmark_type>{benchmark_type::multi_bench, benchmark_type::read_bench}},
_conn{mongocxx::uri{}},
_file_name{std::move(file_name)} {}

Expand Down Expand Up @@ -77,8 +74,7 @@ void gridfs_download::task() {
auto buffer_size = std::min(file_length, static_cast<std::int64_t>(downloader.chunk_size()));
auto buffer = std::make_unique<std::uint8_t[]>(static_cast<std::size_t>(buffer_size));

while ([[maybe_unused]] auto length_read =
downloader.read(buffer.get(), static_cast<std::size_t>(buffer_size))) {
while ([[maybe_unused]] auto length_read = downloader.read(buffer.get(), static_cast<std::size_t>(buffer_size))) {
}
}
} // namespace benchmark
} // namespace benchmark
11 changes: 4 additions & 7 deletions benchmark/multi_doc/gridfs_upload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ class gridfs_upload : public microbench {
public:
// The task size comes from the Driver Perfomance Benchmarking Reference Doc.
gridfs_upload(std::string file_name)
: microbench{"TestGridFsUpload",
52.43,
std::set<benchmark_type>{benchmark_type::multi_bench,
benchmark_type::write_bench}},
: microbench{"TestGridFsUpload", 52.43, std::set<benchmark_type>{benchmark_type::multi_bench, benchmark_type::write_bench}},
_conn{mongocxx::uri{}},
_file_name{file_name} {}

Expand All @@ -60,8 +57,8 @@ class gridfs_upload : public microbench {
void gridfs_upload::setup() {
std::ifstream stream{_file_name};
stream >> std::noskipws;
_gridfs_file = std::vector<std::uint8_t>{(std::istream_iterator<unsigned char>{stream}),
(std::istream_iterator<unsigned char>{})};
_gridfs_file = std::vector<std::uint8_t>{
(std::istream_iterator<unsigned char>{stream}), (std::istream_iterator<unsigned char>{})};

mongocxx::database db = _conn["perftest"];
db.drop();
Expand All @@ -87,4 +84,4 @@ void gridfs_upload::task() {
uploader.write(_gridfs_file.data(), _gridfs_file.size());
uploader.close();
}
} // namespace benchmark
} // namespace benchmark
Loading