@@ -27,8 +27,7 @@ use std::{
27
27
28
28
use anyhow:: Result ;
29
29
use clap:: { App , Arg , ArgMatches } ;
30
- use futures:: Future ;
31
- use futures:: FutureExt ;
30
+ use futures:: { Future , FutureExt } ;
32
31
use mongodb:: options:: ClientOptions ;
33
32
use once_cell:: sync:: Lazy ;
34
33
@@ -62,6 +61,7 @@ const DEEP_BSON_DECODING: &'static str = "Deep BSON Decoding";
62
61
const FULL_BSON_ENCODING : & ' static str = "Full BSON Encoding" ;
63
62
const FULL_BSON_DECODING : & ' static str = "Full BSON Decoding" ;
64
63
const RUN_COMMAND_BENCH : & ' static str = "Run Command" ;
64
+ const RUN_COMMAND_COLD_START_BENCH : & ' static str = "Run Command (cold start)" ;
65
65
const FIND_ONE_BENCH : & ' static str = "Find one" ;
66
66
const FIND_MANY_BENCH : & ' static str = "Find many and empty cursor" ;
67
67
const FIND_MANY_BENCH_RAW : & ' static str = "Find many and empty cursor (raw BSON)" ;
@@ -101,12 +101,14 @@ enum BenchmarkId {
101
101
GridFsUpload ,
102
102
GridFsMultiDownload ,
103
103
GridFsMultiUpload ,
104
+ RunCommandColdStart ,
104
105
}
105
106
106
107
impl BenchmarkId {
107
108
fn name ( self ) -> & ' static str {
108
109
match self {
109
110
BenchmarkId :: RunCommand => RUN_COMMAND_BENCH ,
111
+ BenchmarkId :: RunCommandColdStart => RUN_COMMAND_COLD_START_BENCH ,
110
112
BenchmarkId :: FindOneById => FIND_ONE_BENCH ,
111
113
BenchmarkId :: SmallDocInsertOne => SMALL_DOC_INSERT_ONE_BENCH ,
112
114
BenchmarkId :: LargeDocInsertOne => LARGE_DOC_INSERT_ONE_BENCH ,
@@ -186,7 +188,7 @@ const WRITE_BENCHES: &[&'static str] = &[
186
188
GRIDFS_MULTI_UPLOAD_BENCH ,
187
189
] ;
188
190
189
- const MAX_ID : u8 = BenchmarkId :: GridFsMultiUpload as u8 ;
191
+ const MAX_ID : u8 = BenchmarkId :: RunCommandColdStart as u8 ;
190
192
191
193
async fn run_benchmarks (
192
194
uri : & str ,
@@ -208,13 +210,28 @@ async fn run_benchmarks(
208
210
let run_command_options = bench:: run_command:: Options {
209
211
num_iter : 10000 ,
210
212
uri : uri. to_string ( ) ,
213
+ cold_start : false ,
211
214
} ;
212
215
let run_command =
213
216
bench:: run_benchmark :: < RunCommandBenchmark > ( run_command_options) . await ?;
214
217
215
218
comp_score += score_test ( run_command, RUN_COMMAND_BENCH , 0.13 , more_info) ;
216
219
}
217
220
221
+ // Run command, including client setup time
222
+ BenchmarkId :: RunCommandColdStart => {
223
+ let run_command_options = bench:: run_command:: Options {
224
+ num_iter : 100 ,
225
+ uri : uri. to_string ( ) ,
226
+ cold_start : true ,
227
+ } ;
228
+ let run_command =
229
+ bench:: run_benchmark :: < RunCommandBenchmark > ( run_command_options) . await ?;
230
+
231
+ comp_score +=
232
+ score_test ( run_command, RUN_COMMAND_COLD_START_BENCH , 0.13 , more_info) ;
233
+ }
234
+
218
235
// Small doc insertOne
219
236
BenchmarkId :: SmallDocInsertOne => {
220
237
let small_insert_one_options = bench:: insert_one:: Options {
@@ -530,6 +547,7 @@ fn parse_ids(matches: ArgMatches) -> HashSet<BenchmarkId> {
530
547
531
548
if matches. is_present ( "single" ) {
532
549
ids. insert ( BenchmarkId :: RunCommand ) ;
550
+ ids. insert ( BenchmarkId :: RunCommandColdStart ) ;
533
551
ids. insert ( BenchmarkId :: FindOneById ) ;
534
552
ids. insert ( BenchmarkId :: SmallDocInsertOne ) ;
535
553
ids. insert ( BenchmarkId :: LargeDocInsertOne ) ;
@@ -557,6 +575,7 @@ fn parse_ids(matches: ArgMatches) -> HashSet<BenchmarkId> {
557
575
}
558
576
if matches. is_present ( "driver" ) {
559
577
ids. insert ( BenchmarkId :: RunCommand ) ;
578
+ ids. insert ( BenchmarkId :: RunCommandColdStart ) ;
560
579
ids. insert ( BenchmarkId :: FindOneById ) ;
561
580
ids. insert ( BenchmarkId :: SmallDocInsertOne ) ;
562
581
ids. insert ( BenchmarkId :: LargeDocInsertOne ) ;
@@ -591,6 +610,13 @@ async fn main() {
591
610
"MAX_ID not up to date"
592
611
) ;
593
612
613
+ let mut id_help = String :: from ( "\n Run benchmarks by id number (comma-separated):\n " ) ;
614
+ for ix in 1 ..=MAX_ID {
615
+ let id = BenchmarkId :: try_from ( ix) . unwrap ( ) ;
616
+ id_help. push_str ( & format ! ( " {}: {}\n " , ix, id. name( ) ) ) ;
617
+ }
618
+ id_help. push_str ( " all: All benchmarks\n " ) ;
619
+
594
620
let matches = App :: new ( "RustDriverBenchmark" )
595
621
. version ( env ! ( "CARGO_PKG_VERSION" ) )
596
622
. about ( "Runs performance micro-bench" )
@@ -637,33 +663,7 @@ async fn main() {
637
663
. long ( "ids" )
638
664
. takes_value ( true )
639
665
. help ( "Run benchmarks by id number (comma-separated)" )
640
- . long_help (
641
- "
642
- Run benchmarks by id number (comma-separated):
643
- 1: Run command
644
- 2: Find one by ID
645
- 3: Small doc insertOne
646
- 4: Large doc insertOne
647
- 5: Find many and empty the cursor
648
- 6: Small doc bulk insert
649
- 7: Large doc bulk insert
650
- 8: LDJSON multi-file import
651
- 9: LDJSON multi-file export
652
- 10: BSON flat document decode
653
- 11: BSON flat document encode
654
- 12: BSON deeply nested document decode
655
- 13: BSON deeply nested document encode
656
- 14: BSON full document decode
657
- 15: BSON full document encode
658
- 16: Find many and empty the cursor (raw BSON)
659
- 17: Find many and empty the cursor (serde structs)
660
- 18: GridFS download
661
- 19: GridFS upload
662
- 20: GridFS multi-file download
663
- 21: GridFS multi-file upload
664
- all: All benchmarks
665
- " ,
666
- ) ,
666
+ . long_help ( & id_help) ,
667
667
)
668
668
. arg (
669
669
Arg :: with_name ( "output" )
0 commit comments