From f7d39d72a14f90304e7ba22f95231581427a486f Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Fri, 12 Jul 2024 23:51:41 +0800 Subject: [PATCH] Fix benchmark and update results --- README.md | 8 ++++---- examples/benchmark.rs | 38 ++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b34eef9fd..a92f16904 100644 --- a/README.md +++ b/README.md @@ -513,14 +513,14 @@ cargo run --release --example benchmark -- --tap tap0 [reader|writer] It establishes a connection to itself from a different thread and reads or writes a large amount of data in one direction. -A typical result (achieved on a Intel Core i7-7500U CPU and a Linux 4.9.65 x86_64 kernel running -on a Dell XPS 13 9360 laptop) is as follows: +A typical result (achieved on a Intel Core i5-13500H CPU and a Linux 6.9.9 x86_64 kernel running +on a LENOVO XiaoXinPro 14 IRH8 laptop) is as follows: ``` $ cargo run -q --release --example benchmark -- --tap tap0 reader -throughput: 2.556 Gbps +throughput: 3.673 Gbps $ cargo run -q --release --example benchmark -- --tap tap0 writer -throughput: 5.301 Gbps +throughput: 7.905 Gbps ``` ## Bare-metal usage examples diff --git a/examples/benchmark.rs b/examples/benchmark.rs index ad2c6e142..be1959f6d 100644 --- a/examples/benchmark.rs +++ b/examples/benchmark.rs @@ -1,5 +1,3 @@ -#![allow(clippy::collapsible_if)] - mod utils; use std::cmp; @@ -121,16 +119,14 @@ fn main() { socket.listen(1234).unwrap(); } - if socket.can_send() { - if processed < AMOUNT { - let length = socket - .send(|buffer| { - let length = cmp::min(buffer.len(), AMOUNT - processed); - (length, length) - }) - .unwrap(); - processed += length; - } + while socket.can_send() && processed < AMOUNT { + let length = socket + .send(|buffer| { + let length = cmp::min(buffer.len(), AMOUNT - processed); + (length, length) + }) + .unwrap(); + processed += length; } // tcp:1235: sink data @@ -139,16 +135,14 @@ fn main() { socket.listen(1235).unwrap(); } - if socket.can_recv() { - if processed < AMOUNT { - let length = socket - .recv(|buffer| { - let length = cmp::min(buffer.len(), AMOUNT - processed); - (length, length) - }) - .unwrap(); - processed += length; - } + while socket.can_recv() && processed < AMOUNT { + let length = socket + .recv(|buffer| { + let length = cmp::min(buffer.len(), AMOUNT - processed); + (length, length) + }) + .unwrap(); + processed += length; } match iface.poll_at(timestamp, &sockets) {