2019-01-02 21:16:55 +03:00
extern crate proxmox_backup ;
2024-04-19 16:34:54 +03:00
use pbs_datastore ::{ Chunker , ChunkerImpl } ;
2019-01-02 21:16:55 +03:00
fn main ( ) {
let mut buffer = Vec ::new ( ) ;
2022-04-10 18:44:34 +03:00
for i in 0 .. 20 * 1024 * 1024 {
2019-01-02 21:16:55 +03:00
for j in 0 .. 4 {
2022-04-10 18:44:34 +03:00
let byte = ( ( i > > ( j < < 3 ) ) & 0xff ) as u8 ;
2019-01-02 21:16:55 +03:00
//println!("BYTE {}", byte);
buffer . push ( byte ) ;
}
}
2024-04-19 16:34:54 +03:00
let mut chunker = ChunkerImpl ::new ( 64 * 1024 ) ;
2019-01-02 21:16:55 +03:00
2019-01-03 16:35:19 +03:00
let count = 5 ;
2019-01-02 21:16:55 +03:00
let start = std ::time ::SystemTime ::now ( ) ;
2019-01-03 16:35:19 +03:00
let mut chunk_count = 0 ;
2022-04-10 18:44:34 +03:00
2019-01-02 21:16:55 +03:00
for _i in 0 .. count {
let mut pos = 0 ;
2019-01-30 20:25:37 +03:00
let mut _last = 0 ;
2024-04-19 16:34:54 +03:00
let ctx = pbs_datastore ::chunker ::Context ::default ( ) ;
2019-01-02 21:16:55 +03:00
while pos < buffer . len ( ) {
2024-04-19 16:34:54 +03:00
let k = chunker . scan ( & buffer [ pos .. ] , & ctx ) ;
2019-01-02 21:16:55 +03:00
if k = = 0 {
//println!("LAST {}", pos);
break ;
} else {
2019-01-30 20:25:37 +03:00
_last = pos ;
2019-01-02 21:16:55 +03:00
pos + = k ;
2019-01-03 16:35:19 +03:00
chunk_count + = 1 ;
//println!("CHUNK {} {}", pos, pos-last);
2019-01-02 21:16:55 +03:00
}
}
}
let elapsed = start . elapsed ( ) . unwrap ( ) ;
2022-04-10 18:44:34 +03:00
let elapsed = ( elapsed . as_secs ( ) as f64 ) + ( elapsed . subsec_millis ( ) as f64 ) / 1000.0 ;
let mbytecount = ( ( count * buffer . len ( ) ) as f64 ) / ( 1024.0 * 1024.0 ) ;
let avg_chunk_size = mbytecount / ( chunk_count as f64 ) ;
let mbytes_per_sec = mbytecount / elapsed ;
println! (
" SPEED = {} MB/s, avg chunk size = {} KB " ,
mbytes_per_sec ,
avg_chunk_size * 1024.0
) ;
2019-01-02 21:16:55 +03:00
}