Struct rolling_dual_crc::Zeros [−][src]
pub struct Zeros { /* fields omitted */ }
Expand description
Efficient representation of a 0u8
sequence for DualCrc::update_with_zeros
.
Examples
Compute checksum of "Hello, World!"
padded to 4 kiB by 0u8
:
use rolling_dual_crc::{DualCrc, Zeros};
let data = "Hello, world!";
let padding_size = 4096 - data.as_bytes().len();
let mut crc = DualCrc::new();
crc.update(data);
// This is equivalent to `crc.update(&vec![0u8; padding_size])`
// but more efficient with long sequences.
crc.update_with_zeros(&Zeros::new(padding_size));
assert_eq!(crc.get32(), 0xCED9AB00);
Benchmarks
- These benchmarks are from
cargo bench zeros
with 3.4 GHz i5-3570K (Ivy Bridge, 3rd gen.). - See crate index for main benchmarks.
In these benchmarks update
and update_with_zeros
use sequence lengths
64/256/1024 while Zeros::new
uses sequence lengths 63/64/255/256/1023/1024
because its speed depends on the number of 1-bits in the sequence length.
Low end (best) timings are with 2^n
while high end (worst) timings are with 2^n-1
.
Method | ns / ~64 B | ns / ~256 B | ns / ~1024 B | complexity |
---|---|---|---|---|
DualCrc::update | 65 | 260 | 1000 | Θ(n) |
DualCrc::update_with_zeros | 90 | 90 | 90 | Θ(1) |
Zeros::new | 3 - 430 | 3 - 600 | 3 - 770 | Θ(one_bits n) |
- For short sequences
update
is always faster thanupdate_with_zeros
. - For long sequences
update_with_zeros
withZeros::new
is always faster. - For intermediate sequences situation depends on exact sequence length
and also whether new
Zeros
is created for eachupdate_with_zeros
call, or if sameZeros
is used with multipleupdate_with_zeros
calls, amortizing its creation time.
Implementations
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Zeros
impl UnwindSafe for Zeros
Blanket Implementations
Mutably borrows from an owned value. Read more