14
14
15
15
#include " benchmark_runner.hpp"
16
16
17
+ #include < chrono>
18
+ #include < cstdint>
19
+ #include < fstream>
20
+ #include < iomanip>
21
+ #include < iostream>
22
+ #include < memory>
23
+ #include < sstream>
24
+
17
25
#include " bson/bson_encoding.hpp"
18
26
#include " multi_doc/bulk_insert.hpp"
19
27
#include " multi_doc/find_many.hpp"
26
34
#include " single_doc/find_one_by_id.hpp"
27
35
#include " single_doc/insert_one.hpp"
28
36
#include " single_doc/run_command.hpp"
37
+ #include < bsoncxx/builder/basic/array.hpp>
38
+ #include < bsoncxx/builder/basic/document.hpp>
39
+ #include < bsoncxx/builder/basic/kvp.hpp>
40
+ #include < bsoncxx/builder/basic/sub_document.hpp>
41
+ #include < bsoncxx/json.hpp>
29
42
#include < bsoncxx/stdx/make_unique.hpp>
43
+ #include < bsoncxx/types.hpp>
30
44
31
45
namespace benchmark {
32
46
@@ -47,26 +61,28 @@ benchmark_runner::benchmark_runner(std::set<benchmark_type> types) : _types{type
47
61
_microbenches.push_back (make_unique<run_command>());
48
62
_microbenches.push_back (make_unique<find_one_by_id>(" single_and_multi_document/tweet.json" ));
49
63
_microbenches.push_back (make_unique<insert_one>(
50
- " TestSmallDocInsertOne" , 2.75 , 10000 , " single_and_multi_document/small_doc.json" ));
64
+ " TestSmallDocInsertOne" , 2.75 , iterations , " single_and_multi_document/small_doc.json" ));
51
65
_microbenches.push_back (make_unique<insert_one>(
52
66
" TestLargeDocInsertOne" , 27.31 , 10 , " single_and_multi_document/large_doc.json" ));
53
67
54
68
// Multi doc microbenchmarks
55
69
_microbenches.push_back (make_unique<find_many>(" single_and_multi_document/tweet.json" ));
56
70
_microbenches.push_back (make_unique<bulk_insert>(
57
- " TestSmallDocBulkInsert" , 2.75 , 10000 , " single_and_multi_document/small_doc.json" ));
71
+ " TestSmallDocBulkInsert" , 2.75 , iterations , " single_and_multi_document/small_doc.json" ));
58
72
_microbenches.push_back (make_unique<bulk_insert>(
59
73
" TestLargeDocBulkInsert" , 27.31 , 10 , " single_and_multi_document/large_doc.json" ));
60
- _microbenches.push_back (
61
- make_unique<gridfs_upload>(" single_and_multi_document/gridfs_large.bin" ));
62
- _microbenches.push_back (
63
- make_unique<gridfs_download>(" single_and_multi_document/gridfs_large.bin" ));
74
+ // CXX-2794: Disable GridFS benchmarks due to long runtime
75
+ // _microbenches.push_back(
76
+ // make_unique<gridfs_upload>("single_and_multi_document/gridfs_large.bin"));
77
+ // _microbenches.push_back(
78
+ // make_unique<gridfs_download>("single_and_multi_document/gridfs_large.bin"));
64
79
65
80
// Parallel microbenchmarks
66
81
_microbenches.push_back (make_unique<json_multi_import>(" parallel/ldjson_multi" ));
67
82
_microbenches.push_back (make_unique<json_multi_export>(" parallel/ldjson_multi" ));
68
- _microbenches.push_back (make_unique<gridfs_multi_import>(" parallel/gridfs_multi" ));
69
- _microbenches.push_back (make_unique<gridfs_multi_export>(" parallel/gridfs_multi" ));
83
+ // CXX-2794: Disable GridFS benchmarks due to long runtime
84
+ // _microbenches.push_back(make_unique<gridfs_multi_import>("parallel/gridfs_multi"));
85
+ // _microbenches.push_back(make_unique<gridfs_multi_export>("parallel/gridfs_multi"));
70
86
71
87
// Need to remove some
72
88
if (!_types.empty ()) {
@@ -89,8 +105,7 @@ benchmark_runner::benchmark_runner(std::set<benchmark_type> types) : _types{type
89
105
}
90
106
91
107
void benchmark_runner::run_microbenches () {
92
- mongocxx::instance instance{};
93
-
108
+ _start_time = std::chrono::system_clock::now ();
94
109
for (std::unique_ptr<microbench>& bench : _microbenches) {
95
110
std::cout << " Starting " << bench->get_name () << " ..." << std::endl;
96
111
@@ -103,6 +118,7 @@ void benchmark_runner::run_microbenches() {
103
118
<< " second(s) | " << score.get_score () << " MB/s" << std::endl
104
119
<< std::endl;
105
120
}
121
+ _end_time = std::chrono::system_clock::now ();
106
122
}
107
123
108
124
double benchmark_runner::calculate_average (benchmark_type tag) {
@@ -145,20 +161,48 @@ double benchmark_runner::calculate_driver_bench_score() {
145
161
return (calculate_read_bench_score () + calculate_write_bench_score ()) / 2.0 ;
146
162
}
147
163
148
- void benchmark_runner::print_scores () {
164
+ void benchmark_runner::write_scores () {
149
165
double read = -1 ;
150
166
double write = -1 ;
151
167
168
+ using namespace bsoncxx ;
169
+ using builder::basic::sub_document;
170
+
171
+ auto doc = builder::basic::document{};
172
+ doc.append (kvp (" info" , [](sub_document subdoc) {
173
+ subdoc.append (kvp (" test_name" , " C++ Driver microbenchmarks" ));
174
+ }));
175
+
176
+ auto write_time =
177
+ [](const std::chrono::time_point<std::chrono::system_clock> t) -> std::string {
178
+ std::time_t t1 = std::chrono::system_clock::to_time_t (t);
179
+ std::ostringstream oss;
180
+ oss << std::put_time (std::gmtime (&t1), " %Y-%m-%dT%H:%M:%S" ) << " +00:00" ;
181
+ return oss.str ();
182
+ };
183
+ doc.append (kvp (" created_at" , write_time (_start_time)));
184
+ doc.append (kvp (" completed_at" , write_time (_end_time)));
185
+ doc.append (kvp (" artifacts" , builder::basic::make_array ()));
186
+
187
+ auto metrics_array = builder::basic::array{};
188
+ std::cout << std::endl << " Composite benchmarks:" << std::endl << " ===========" << std::endl;
189
+
152
190
std::cout << " Individual microbenchmark scores:" << std::endl << " ===========" << std::endl;
153
191
for (auto && bench : _microbenches) {
154
192
auto & score = bench->get_results ();
193
+ const auto bench_time = static_cast <double >(score.get_percentile (50 ).count ()) / 1000.0 ;
155
194
156
- std::cout << bench->get_name () << " : "
157
- << static_cast <double >(score.get_percentile (50 ).count ()) / 1000.0
158
- << " second(s) | " << score.get_score () << " MB/s" << std::endl;
159
- }
195
+ std::cout << bench->get_name () << " : " << bench_time << " seconds | " << score.get_score ()
196
+ << " MB/s" << std::endl;
160
197
161
- std::cout << std::endl << " Composite benchmarks:" << std::endl << " ===========" << std::endl;
198
+ auto metric_doc = builder::basic::document{};
199
+ metric_doc.append (kvp (" name" , bench->get_name ()));
200
+ metric_doc.append (kvp (" type" , " THROUGHPUT" ));
201
+ metric_doc.append (kvp (" value" , score.get_score ()));
202
+ metrics_array.append (metric_doc);
203
+ }
204
+ doc.append (kvp (" metrics" , metrics_array));
205
+ doc.append (kvp (" sub_tests" , builder::basic::make_array ()));
162
206
163
207
auto print_comp = [this , &read, &write](benchmark_type type) {
164
208
double avg = calculate_average (type);
@@ -169,7 +213,7 @@ void benchmark_runner::print_scores() {
169
213
write = avg;
170
214
}
171
215
172
- std::cout << type_names[ type] << " " << avg << " MB/s" << std::endl;
216
+ std::cout << type_names. at ( type) << " " << avg << " MB/s" << std::endl;
173
217
};
174
218
175
219
if (!_types.empty ()) {
@@ -185,5 +229,8 @@ void benchmark_runner::print_scores() {
185
229
if (read > 0 && write > 0 ) {
186
230
std::cout << " DriverBench: " << (read + write) / 2.0 << " MB/s" << std::endl;
187
231
}
232
+
233
+ std::ofstream os{" results.json" };
234
+ os << ' [' << bsoncxx::to_json (doc.view ()) << ' ]' ;
188
235
}
189
236
} // namespace benchmark
0 commit comments