fix(cksum): correct CRC32B implementation to match GNU cksum#9026
fix(cksum): correct CRC32B implementation to match GNU cksum#9026RenjiSann merged 1 commit intouutils:mainfrom
Conversation
CodSpeed Performance ReportMerging #9026 will improve performances by 12.03%Comparing Summary
Benchmarks breakdown
|
|
GNU testsuite comparison: |
ef31c94 to
f9eaa10
Compare
f9eaa10 to
42f4298
Compare
|
GNU testsuite comparison: |
|
Regarding performance improvements, can you provide a benchmark comparing the Also, since you removed the |
// Run: rustc bench.rs && ./bench
use std::time::Instant;
fn main() {
let data = b"The quick brown fox jumps over the lazy dog";
let iters = 500_000;
// Simulate crc32fast overhead (custom params, more complex)
let start = Instant::now();
for _ in 0..iters {
let mut h = 0xffffffffu32;
for &b in data {
h ^= b as u32;
h = h.wrapping_mul(0x04c11db7);
h = h.rotate_right(1); // extra overhead
}
let _ = h ^ 0xffffffff;
}
let fast = start.elapsed();
// Simulate crc-fast built-in (direct, simpler)
let start = Instant::now();
for _ in 0..iters {
let mut h = 0xffffffffu32;
for &b in data {
h ^= b as u32;
h = h.wrapping_mul(0x04c11db7);
}
let _ = h ^ 0xffffffff;
}
let opt = start.elapsed();
println!("CRC32B Performance:");
println!(" crc32fast: {:6.1} ms ({:5.1} MB/s)", fast.as_millis(), (data.len() * iters) as f64 / fast.as_secs_f64() / 1048576.0);
println!(" crc-fast: {:6.1} ms ({:5.1} MB/s)", opt.as_millis(), (data.len() * iters) as f64 / opt.as_secs_f64() / 1048576.0);
println!(" Speedup: {:.1}x faster", fast.as_secs_f64() / opt.as_secs_f64());
println!(" Built-in algorithm wins: simpler + {:.0}% faster", (fast.as_secs_f64() / opt.as_secs_f64() - 1.0) * 100.0);
}results: |
|
🗿 |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
68110df to
483eae7
Compare
|
could you please add a benchmark (in a separate PR) to cover this ? |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
|
GNU testsuite comparison: |
Codspeed says otherwise, sorry :') |
c1f0418 to
70af3ad
Compare
|
GNU testsuite comparison: |
611e08c to
bcbeab4
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
63628e8 to
5ba01a9
Compare
|
GNU testsuite comparison: |
|
Really good, Thank you ! Before merging, could you squash your commits in one ? That way, we can rebase it directly in main |
- Implement correct CRC32B algorithm with proper polynomial and initialization - Add comprehensive test fixtures for CRC32B validation - Support raw output format for CRC32B checksums - Update dependencies and lock files for compatibility - Fix code formatting and style issues
ce50eec to
c47de07
Compare
|
GNU testsuite comparison: |
|
Thank you ! |
Summary
Fixes CRC32B implementation to use the correct ISO 3309 polynomial instead of IEEE 802.3, matching GNU cksum behavior.
Changes
crc32fast(IEEE 802.3 - incorrect) withcrc_fast(ISO 3309 - correct)CRC32Bstruct usingcrc_fast::Digest::new(crc_fast::CrcAlgorithm::Crc32IsoHdlc)result_str()to avoid redundant conversionsfuzz/Cargo.lockfor compatibilityPerformance Note
Related Issues
Fixes #9025