11use std:: borrow:: Cow ;
2- use std:: io:: { Sink , Write as _, repeat } ;
2+ use std:: io:: { Sink , Write as _} ;
33use std:: path:: PathBuf ;
44use std:: time:: Duration ;
55
@@ -13,7 +13,7 @@ use testcontainers::core::{ContainerPort, WaitFor};
1313use testcontainers:: { Container , Image } ;
1414
1515const P : & str = "/tmp/large_file" ;
16- const WRITE_SIZE : u64 = 2 * 1024 * 1024 * 1024 ; // 2GB
16+ const WRITE_SIZE : u64 = 2 * 1024 * 1024 ; // 2MB
1717
1818fn benchmark_scp_read ( c : & mut Criterion ) {
1919 c. bench_function ( "scp_read" , |b| {
@@ -33,6 +33,7 @@ fn benchmark_scp_read(c: &mut Criterion) {
3333 } ) ;
3434}
3535
36+ /*
3637fn benchmark_scp_write(c: &mut Criterion) {
3738 c.bench_function("scp_write", |b| {
3839 b.iter_batched(
@@ -54,6 +55,7 @@ fn benchmark_scp_write(c: &mut Criterion) {
5455 );
5556 });
5657}
58+ */
5759
5860fn benchmark_sftp_read ( c : & mut Criterion ) {
5961 c. bench_function ( "sftp_read" , |b| {
@@ -73,6 +75,7 @@ fn benchmark_sftp_read(c: &mut Criterion) {
7375 } ) ;
7476}
7577
78+ /*
7679fn benchmark_sftp_write(c: &mut Criterion) {
7780 c.bench_function("sftp_write", |b| {
7881 b.iter_batched(
@@ -94,6 +97,7 @@ fn benchmark_sftp_write(c: &mut Criterion) {
9497 );
9598 });
9699}
100+ */
97101
98102struct BenchmarkCtx {
99103 _container : OpensshServer ,
@@ -129,15 +133,12 @@ impl BenchmarkCtx {
129133 let file_to_transfer = PathBuf :: from ( P ) ;
130134 // open file
131135 let mut writer = client
132- . create (
133- & file_to_transfer,
134- & Metadata :: default ( ) . size ( 2 * 1024 * 1024 * 1024 ) ,
135- )
136+ . create ( & file_to_transfer, & Metadata :: default ( ) . size ( WRITE_SIZE ) )
136137 . unwrap ( ) ;
137138 let mut written = 0 ;
138139 let buf = [ 0 ; 1024 * 1024 ] ;
139140 loop {
140- let to_write = buf. len ( ) . min ( 2 * 1024 * 1024 * 1024 - written) ;
141+ let to_write = buf. len ( ) . min ( WRITE_SIZE as usize - written) ;
141142 if to_write == 0 {
142143 break ;
143144 }
@@ -169,15 +170,12 @@ impl BenchmarkCtx {
169170 let file_to_transfer = PathBuf :: from ( P ) ;
170171 // open file
171172 let mut writer = client
172- . create (
173- & file_to_transfer,
174- & Metadata :: default ( ) . size ( 2 * 1024 * 1024 * 1024 ) ,
175- )
173+ . create ( & file_to_transfer, & Metadata :: default ( ) . size ( WRITE_SIZE ) )
176174 . unwrap ( ) ;
177175 let mut written = 0 ;
178176 let buf = [ 0 ; 1024 * 1024 ] ;
179177 loop {
180- let to_write = buf. len ( ) . min ( 2 * 1024 * 1024 * 1024 - written) ;
178+ let to_write = buf. len ( ) . min ( WRITE_SIZE as usize - written) ;
181179 if to_write == 0 {
182180 break ;
183181 }
@@ -353,7 +351,7 @@ fn generate_tempdir() -> String {
353351
354352fn configure_criterion ( ) -> Criterion {
355353 Criterion :: default ( )
356- . measurement_time ( std:: time:: Duration :: from_secs ( 420 ) ) // measure time
354+ . measurement_time ( std:: time:: Duration :: from_secs ( 100 ) ) // measure time
357355 . warm_up_time ( std:: time:: Duration :: from_secs ( 15 ) )
358356 . sample_size ( 10 ) // samples
359357}
@@ -362,8 +360,8 @@ criterion_group!(
362360 name = benches;
363361 config = configure_criterion( ) ;
364362 targets = benchmark_scp_read,
365- benchmark_scp_write,
363+ // benchmark_scp_write,
366364 benchmark_sftp_read,
367- benchmark_sftp_write
365+ // benchmark_sftp_write
368366) ;
369367criterion_main ! ( benches) ;
0 commit comments