Skip to content

Commit c44b295

Browse files
authored
Merge pull request #695 from hermit-os/netbench-update
feat(netbench): print bandwidth for each round
2 parents 48b374a + 4f6ca53 commit c44b295

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

benches/netbench/src/rust-tcp-bw/client.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ fn main() {
1212
let args = Config::parse();
1313

1414
println!("Connecting to the server {}...", args.address);
15-
let n_rounds = args.n_rounds;
16-
let n_bytes = args.n_bytes;
1715

1816
if let Ok(mut stream) = connection::client_connect(args.address_and_port()) {
1917
connection::setup(&args, &stream);
2018
println!("Connection established! Ready to send...");
2119

2220
// Create a buffer of 0s, size n_bytes, to be sent over multiple times
23-
let buf = vec![0; n_bytes];
21+
let buf = vec![0; args.n_bytes];
2422

25-
for _i in 0..n_rounds {
23+
for _i in 0..args.n_rounds {
2624
let mut pos = 0;
2725

2826
while pos < buf.len() {

benches/netbench/src/rust-tcp-bw/server.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@ use rust_tcp_io_perf::{connection, print_utils};
1111

1212
fn main() {
1313
let args = Config::parse();
14-
let n_bytes = args.n_bytes;
1514
let tot_bytes = args.n_rounds * args.n_bytes;
1615

17-
let mut buf = vec![0; n_bytes];
16+
let mut buf = vec![0; args.n_bytes];
1817

1918
let mut stream = connection::server_listen_and_get_first_connection(&args.port.to_string());
2019
connection::setup(&args, &stream);
2120

2221
let start = Instant::now();
23-
for _i in 0..args.n_rounds {
22+
for i in 0..args.n_rounds {
23+
print!("round {i}: ");
24+
let round_start = Instant::now();
2425
stream.read_exact(&mut buf).unwrap();
26+
let round_end = Instant::now();
27+
let duration = round_end.duration_since(round_start);
28+
let mbits = buf.len() as f64 * 8.0f64 / (1024.0f64 * 1024.0f64 * duration.as_secs_f64());
29+
println!("{mbits} Mbit/s");
2530
}
2631
let end = Instant::now();
2732
let duration = end.duration_since(start);

0 commit comments

Comments
 (0)