Unswitch the IP checksum loop for 30% improvement in performance.
This commit is contained in:
parent
fb11c4a84d
commit
d8685dbb1e
|
@ -316,9 +316,9 @@ on a Dell XPS 13 9360 laptop) is as follows:
|
|||
|
||||
```
|
||||
$ cargo run -q --release --example benchmark tap0 reader
|
||||
throughput: 2.219 Gbps
|
||||
throughput: 2.556 Gbps
|
||||
$ cargo run -q --release --example benchmark tap0 writer
|
||||
throughput: 4.519 Gbps
|
||||
throughput: 5.301 Gbps
|
||||
```
|
||||
|
||||
## Bare-metal usage examples
|
||||
|
|
|
@ -610,18 +610,15 @@ pub mod checksum {
|
|||
}
|
||||
|
||||
/// Compute an RFC 1071 compliant checksum (without the final complement).
|
||||
pub fn data(data: &[u8]) -> u16 {
|
||||
pub fn data(mut data: &[u8]) -> u16 {
|
||||
// See RFC 1071 section 4.1 for the original implementation.
|
||||
let mut accum: u32 = 0;
|
||||
let mut i = 0;
|
||||
while i < data.len() {
|
||||
let word;
|
||||
if i + 2 <= data.len() {
|
||||
word = NetworkEndian::read_u16(&data[i..i + 2]) as u32
|
||||
} else {
|
||||
word = (data[i] as u32) << 8
|
||||
}
|
||||
accum += word;
|
||||
i += 2;
|
||||
while data.len() >= 2 {
|
||||
accum += NetworkEndian::read_u16(data) as u32;
|
||||
data = &data[2..];
|
||||
}
|
||||
if let Some(&value) = data.first() {
|
||||
accum += (value as u32) << 8;
|
||||
}
|
||||
propagate_carries(accum)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue