mirror of
https://github.com/CompeyDev/ruck.git
synced 2025-01-08 11:49:09 +00:00
Add some benchmark for upload
This commit is contained in:
parent
6bc011c910
commit
bb32cf8686
1 changed files with 16 additions and 0 deletions
|
@ -12,6 +12,7 @@ use flate2::bufread::GzEncoder;
|
||||||
use flate2::write::GzDecoder;
|
use flate2::write::GzDecoder;
|
||||||
use flate2::Compression;
|
use flate2::Compression;
|
||||||
use std::io::{BufReader, Read, Write};
|
use std::io::{BufReader, Read, Write};
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
ms: MessageStream,
|
ms: MessageStream,
|
||||||
|
@ -53,12 +54,17 @@ impl Connection {
|
||||||
let mut buffer = [0; BUFFER_SIZE];
|
let mut buffer = [0; BUFFER_SIZE];
|
||||||
let reader = BufReader::new(handle.file);
|
let reader = BufReader::new(handle.file);
|
||||||
let mut gz = GzEncoder::new(reader, Compression::fast());
|
let mut gz = GzEncoder::new(reader, Compression::fast());
|
||||||
|
let before = Instant::now();
|
||||||
|
let mut count = 0;
|
||||||
|
let mut bytes_sent: u64 = 0;
|
||||||
loop {
|
loop {
|
||||||
|
count += 1;
|
||||||
match gz.read(&mut buffer) {
|
match gz.read(&mut buffer) {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
|
bytes_sent += n as u64;
|
||||||
let message = Message::FileTransfer(FileTransferPayload {
|
let message = Message::FileTransfer(FileTransferPayload {
|
||||||
chunk: BytesMut::from(&buffer[..n]).freeze(),
|
chunk: BytesMut::from(&buffer[..n]).freeze(),
|
||||||
chunk_header: ChunkHeader {
|
chunk_header: ChunkHeader {
|
||||||
|
@ -71,6 +77,16 @@ impl Connection {
|
||||||
Err(e) => return Err(anyhow!(e.to_string())),
|
Err(e) => return Err(anyhow!(e.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let elapsed = before.elapsed();
|
||||||
|
let mb_sent = bytes_sent / 1_048_576;
|
||||||
|
println!(
|
||||||
|
"{:?} mb sent, {:?} iterations. {:?} total time, {:?} avg per iteration, {:?} avg mb/sec",
|
||||||
|
mb_sent,
|
||||||
|
count,
|
||||||
|
elapsed,
|
||||||
|
elapsed / count,
|
||||||
|
mb_sent / elapsed.as_secs()
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue