Hi all,
Thank you in advance for replying to this thread.
I’m currently implementing a program that capture the time taken for find operation of a time range. However, I’m not sure if the snippets of code below are considered as a proper representation of MongoDB’s performance.
It would be great if I could get some pointer on how to best iterate over a cursor and capture its execution time with performance in mind.
EX 1: Using distance as an attempt to execute all elements in cursor
// Create document
start = std::chrono::high_resolution_clock::now();
auto currDocument = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("timestamp",
bsoncxx::builder::basic::make_document(
bsoncxx::builder::basic::kvp("$gte", bsoncxx::types::b_date(std::chrono::seconds(queryStartTime))), bsoncxx::builder::basic::kvp("$lte", bsoncxx::types::b_date(std::chrono::seconds(queryEndTime))))));
// Dispatch query
mongocxx::cursor cursor = mongoCollection.find(currDocument.view());
std::distance(cursor.begin(), cursor.end());
end = std::chrono::high_resolution_clock::now();
EX 2: Loop over all elements in cursor without doing anything. Note that it is on-purpose not to perform to_json here since that would negatively impact the performance.
`
// Create document
start = std::chrono::high_resolution_clock::now();
auto currDocument = bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp(“timestamp”,
bsoncxx::builder::basic::make_document(
bsoncxx::builder::basic::kvp(“$gte”, bsoncxx::types::b_date(std::chrono::seconds(queryStartTime))), bsoncxx::builder::basic::kvp(“$lte”, bsoncxx::types::b_date(std::chrono::seconds(queryEndTime))))));
// Dispatch query
mongocxx::cursor cursor = mongoCollection.find(currDocument.view());
for (bsoncxx::document::view currDoc : cursor) { }
end = std::chrono::high_resolution_clock::now();
`