@@ -446,6 +446,31 @@ fn write_all_std(b: &mut Bencher, (path, content): &(&Path, &[u8])) {
446446    } ) 
447447} 
448448
449+ fn  write_all_tokio ( b :  & mut  Bencher ,  ( path,  content) :  & ( & Path ,  & [ u8 ] ) )  { 
450+     let  runtime = tokio:: runtime:: Builder :: new_current_thread ( ) 
451+         . enable_all ( ) 
452+         . build ( ) 
453+         . unwrap ( ) ; 
454+     b. to_async ( & runtime) . iter_custom ( |iter| async  move  { 
455+         let  mut  file = tokio:: fs:: File :: create ( path) . await . unwrap ( ) ; 
456+ 
457+         let  start = Instant :: now ( ) ; 
458+         for  _i in  0 ..iter { 
459+             file. seek ( SeekFrom :: Start ( 0 ) ) . await . unwrap ( ) ; 
460+             let  mut  write_len = 0 ; 
461+             let  total_len = content. len ( ) ; 
462+             while  write_len < total_len { 
463+                 let  write = file
464+                     . write ( & content[ write_len..( write_len + BUFFER_SIZE ) . min ( total_len) ] ) 
465+                     . await 
466+                     . unwrap ( ) ; 
467+                 write_len += write; 
468+             } 
469+         } 
470+         start. elapsed ( ) 
471+     } ) 
472+ } 
473+ 
449474fn  write_all_compio ( b :  & mut  Bencher ,  ( path,  content) :  & ( & Path ,  & [ u8 ] ) )  { 
450475    let  runtime = compio:: runtime:: Runtime :: new ( ) . unwrap ( ) ; 
451476    let  content = content. to_vec ( ) ; 
@@ -587,6 +612,7 @@ fn write(c: &mut Criterion) {
587612    group. throughput ( Throughput :: Bytes ( content. len ( )  as  _ ) ) ; 
588613
589614    group. bench_with_input :: < _ ,  _ ,  ( & Path ,  & [ u8 ] ) > ( "std" ,  & ( & path,  & content) ,  write_all_std) ; 
615+     group. bench_with_input :: < _ ,  _ ,  ( & Path ,  & [ u8 ] ) > ( "tokio" ,  & ( & path,  & content) ,  write_all_tokio) ; 
590616    group. bench_with_input :: < _ ,  _ ,  ( & Path ,  & [ u8 ] ) > ( "compio" ,  & ( & path,  & content) ,  write_all_compio) ; 
591617    #[ cfg( target_os = "linux" ) ]  
592618    group. bench_with_input :: < _ ,  _ ,  ( & Path ,  & [ u8 ] ) > ( "monoio" ,  & ( & path,  & content) ,  write_all_monoio) ; 
0 commit comments