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,27 @@ 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
+ // _microbenches.push_back(make_unique<gridfs_multi_import>("parallel/gridfs_multi"));
84
+ // _microbenches.push_back(make_unique<gridfs_multi_export>("parallel/gridfs_multi"));
70
85
71
86
// Need to remove some
72
87
if (!_types.empty ()) {
@@ -89,8 +104,6 @@ benchmark_runner::benchmark_runner(std::set<benchmark_type> types) : _types{type
89
104
}
90
105
91
106
void benchmark_runner::run_microbenches () {
92
- mongocxx::instance instance{};
93
-
94
107
for (std::unique_ptr<microbench>& bench : _microbenches) {
95
108
std::cout << " Starting " << bench->get_name () << " ..." << std::endl;
96
109
@@ -145,20 +158,50 @@ double benchmark_runner::calculate_driver_bench_score() {
145
158
return (calculate_read_bench_score () + calculate_write_bench_score ()) / 2.0 ;
146
159
}
147
160
148
- void benchmark_runner::print_scores () {
161
+ void benchmark_runner::write_scores (
162
+ const std::chrono::time_point<std::chrono::system_clock> start_time) {
149
163
double read = -1 ;
150
164
double write = -1 ;
165
+ const auto end_time = std::chrono::system_clock::now ();
166
+
167
+ using namespace bsoncxx ;
168
+ using builder::basic::sub_document;
169
+
170
+ auto doc = builder::basic::document{};
171
+ doc.append (kvp (" info" , [](sub_document subdoc) {
172
+ subdoc.append (kvp (" test_name" , " C++ microbenchmarks" ));
173
+ }));
174
+
175
+ auto write_time =
176
+ [](const std::chrono::time_point<std::chrono::system_clock> t) -> std::string {
177
+ std::time_t t1 = std::chrono::system_clock::to_time_t (t);
178
+ std::ostringstream oss;
179
+ oss << std::put_time (std::gmtime (&t1), " %Y-%m-%dT%H:%M:%S" ) << " +00:00" ;
180
+ return oss.str ();
181
+ };
182
+ doc.append (kvp (" created_at" , write_time (start_time)));
183
+ doc.append (kvp (" completed_at" , write_time (end_time)));
184
+ doc.append (kvp (" artifacts" , builder::basic::make_array ()));
185
+
186
+ auto metrics_array = builder::basic::array{};
187
+ std::cout << std::endl << " Composite benchmarks:" << std::endl << " ===========" << std::endl;
151
188
152
189
std::cout << " Individual microbenchmark scores:" << std::endl << " ===========" << std::endl;
153
190
for (auto && bench : _microbenches) {
154
191
auto & score = bench->get_results ();
192
+ const auto bench_time = static_cast <double >(score.get_percentile (50 ).count ()) / 1000.0 ;
155
193
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
- }
194
+ std::cout << bench->get_name () << " : " << bench_time << " seconds | " << score.get_score ()
195
+ << " MB/s" << std::endl;
160
196
161
- std::cout << std::endl << " Composite benchmarks:" << std::endl << " ===========" << std::endl;
197
+ auto metric_doc = builder::basic::document{};
198
+ metric_doc.append (kvp (" name" , bench->get_name ()));
199
+ metric_doc.append (kvp (" type" , " THROUGHPUT" ));
200
+ metric_doc.append (kvp (" value" , score.get_score ()));
201
+ metrics_array.append (metric_doc);
202
+ }
203
+ doc.append (kvp (" metrics" , metrics_array));
204
+ doc.append (kvp (" sub_tests" , builder::basic::make_array ()));
162
205
163
206
auto print_comp = [this , &read, &write](benchmark_type type) {
164
207
double avg = calculate_average (type);
@@ -169,7 +212,7 @@ void benchmark_runner::print_scores() {
169
212
write = avg;
170
213
}
171
214
172
- std::cout << type_names[ type] << " " << avg << " MB/s" << std::endl;
215
+ std::cout << type_names. at ( type) << " " << avg << " MB/s" << std::endl;
173
216
};
174
217
175
218
if (!_types.empty ()) {
@@ -185,5 +228,8 @@ void benchmark_runner::print_scores() {
185
228
if (read > 0 && write > 0 ) {
186
229
std::cout << " DriverBench: " << (read + write) / 2.0 << " MB/s" << std::endl;
187
230
}
231
+
232
+ std::ofstream os{" results.json" };
233
+ os << ' [' << bsoncxx::to_json (doc.view ()) << ' ]' ;
188
234
}
189
235
} // namespace benchmark
0 commit comments