@@ -70,4 +70,40 @@ criterion_group!(
7070 bench_insert_to_collection
7171) ;
7272
73- criterion_main ! ( collection) ;
73+ fn bench_save_collection_to_database ( criterion : & mut Criterion ) {
74+ let id = "save collection to database" ;
75+
76+ // Setup the database and collection.
77+ let collection = build_test_collection ( DIMENSION , COLLECTION_SIZE ) ;
78+ let mut db = create_test_database ( DIMENSION , COLLECTION_SIZE ) ;
79+
80+ // Benchmark the save speed.
81+ criterion. bench_function ( id, |bencher| {
82+ bencher. iter ( || {
83+ black_box ( db. save_collection ( "bench" , & collection) . unwrap ( ) ) ;
84+ } )
85+ } ) ;
86+ }
87+
88+ fn bench_get_collection_from_database ( criterion : & mut Criterion ) {
89+ let id = "get collection from database" ;
90+ let db = create_test_database ( DIMENSION , COLLECTION_SIZE ) ;
91+
92+ // Benchmark the get speed.
93+ // This is the operation that loads the collection into memory.
94+ let routine = || {
95+ black_box ( db. get_collection ( "bench" ) . unwrap ( ) ) ;
96+ } ;
97+
98+ criterion. bench_function ( id, |b| b. iter ( routine) ) ;
99+ }
100+
101+ criterion_group ! {
102+ name = database;
103+ config = Criterion :: default ( ) . sample_size( 10 ) ;
104+ targets =
105+ bench_save_collection_to_database,
106+ bench_get_collection_from_database
107+ }
108+
109+ criterion_main ! ( collection, database) ;
0 commit comments