@@ -27,8 +27,7 @@ use std::{
2727
2828use anyhow:: Result ;
2929use clap:: { App , Arg , ArgMatches } ;
30- use futures:: Future ;
31- use futures:: FutureExt ;
30+ use futures:: { Future , FutureExt } ;
3231use mongodb:: options:: ClientOptions ;
3332use once_cell:: sync:: Lazy ;
3433
@@ -62,6 +61,7 @@ const DEEP_BSON_DECODING: &'static str = "Deep BSON Decoding";
6261const FULL_BSON_ENCODING : & ' static str = "Full BSON Encoding" ;
6362const FULL_BSON_DECODING : & ' static str = "Full BSON Decoding" ;
6463const RUN_COMMAND_BENCH : & ' static str = "Run Command" ;
64+ const RUN_COMMAND_COLD_START_BENCH : & ' static str = "Run Command (cold start)" ;
6565const FIND_ONE_BENCH : & ' static str = "Find one" ;
6666const FIND_MANY_BENCH : & ' static str = "Find many and empty cursor" ;
6767const FIND_MANY_BENCH_RAW : & ' static str = "Find many and empty cursor (raw BSON)" ;
@@ -101,12 +101,14 @@ enum BenchmarkId {
101101 GridFsUpload ,
102102 GridFsMultiDownload ,
103103 GridFsMultiUpload ,
104+ RunCommandColdStart ,
104105}
105106
106107impl BenchmarkId {
107108 fn name ( self ) -> & ' static str {
108109 match self {
109110 BenchmarkId :: RunCommand => RUN_COMMAND_BENCH ,
111+ BenchmarkId :: RunCommandColdStart => RUN_COMMAND_COLD_START_BENCH ,
110112 BenchmarkId :: FindOneById => FIND_ONE_BENCH ,
111113 BenchmarkId :: SmallDocInsertOne => SMALL_DOC_INSERT_ONE_BENCH ,
112114 BenchmarkId :: LargeDocInsertOne => LARGE_DOC_INSERT_ONE_BENCH ,
@@ -186,7 +188,7 @@ const WRITE_BENCHES: &[&'static str] = &[
186188 GRIDFS_MULTI_UPLOAD_BENCH ,
187189] ;
188190
189- const MAX_ID : u8 = BenchmarkId :: GridFsMultiUpload as u8 ;
191+ const MAX_ID : u8 = BenchmarkId :: RunCommandColdStart as u8 ;
190192
191193async fn run_benchmarks (
192194 uri : & str ,
@@ -208,13 +210,28 @@ async fn run_benchmarks(
208210 let run_command_options = bench:: run_command:: Options {
209211 num_iter : 10000 ,
210212 uri : uri. to_string ( ) ,
213+ cold_start : false ,
211214 } ;
212215 let run_command =
213216 bench:: run_benchmark :: < RunCommandBenchmark > ( run_command_options) . await ?;
214217
215218 comp_score += score_test ( run_command, RUN_COMMAND_BENCH , 0.13 , more_info) ;
216219 }
217220
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+
218235 // Small doc insertOne
219236 BenchmarkId :: SmallDocInsertOne => {
220237 let small_insert_one_options = bench:: insert_one:: Options {
@@ -530,6 +547,7 @@ fn parse_ids(matches: ArgMatches) -> HashSet<BenchmarkId> {
530547
531548 if matches. is_present ( "single" ) {
532549 ids. insert ( BenchmarkId :: RunCommand ) ;
550+ ids. insert ( BenchmarkId :: RunCommandColdStart ) ;
533551 ids. insert ( BenchmarkId :: FindOneById ) ;
534552 ids. insert ( BenchmarkId :: SmallDocInsertOne ) ;
535553 ids. insert ( BenchmarkId :: LargeDocInsertOne ) ;
@@ -557,6 +575,7 @@ fn parse_ids(matches: ArgMatches) -> HashSet<BenchmarkId> {
557575 }
558576 if matches. is_present ( "driver" ) {
559577 ids. insert ( BenchmarkId :: RunCommand ) ;
578+ ids. insert ( BenchmarkId :: RunCommandColdStart ) ;
560579 ids. insert ( BenchmarkId :: FindOneById ) ;
561580 ids. insert ( BenchmarkId :: SmallDocInsertOne ) ;
562581 ids. insert ( BenchmarkId :: LargeDocInsertOne ) ;
@@ -591,6 +610,13 @@ async fn main() {
591610 "MAX_ID not up to date"
592611 ) ;
593612
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+
594620 let matches = App :: new ( "RustDriverBenchmark" )
595621 . version ( env ! ( "CARGO_PKG_VERSION" ) )
596622 . about ( "Runs performance micro-bench" )
@@ -637,33 +663,7 @@ async fn main() {
637663 . long ( "ids" )
638664 . takes_value ( true )
639665 . 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) ,
667667 )
668668 . arg (
669669 Arg :: with_name ( "output" )
0 commit comments