|
1 | 1 | # CRC32
|
2 | 2 |
|
| 3 | +> Fastest CRC32 Rust Implementation |
| 4 | +
|
3 | 5 | Resurrecting the [`crc32`](https://crates.io/crates/crc32) crate from the ashes.
|
4 | 6 |
|
5 | 7 | ### Usage
|
@@ -46,4 +48,71 @@ fn main() {
|
46 | 48 |
|
47 | 49 | // CRC-32: ebe6c6e6
|
48 | 50 | // CRC-32 (Little Endian): a29eb9bf
|
49 |
| -``` |
| 51 | +``` |
| 52 | + |
| 53 | +### Benchmark |
| 54 | + |
| 55 | +Running `cargo bench` provides the following performance insights: |
| 56 | + |
| 57 | +<details> |
| 58 | +<summary><code>cargo bench</code></summary> |
| 59 | + |
| 60 | +```sh |
| 61 | +cargo bench |
| 62 | + |
| 63 | + Compiling crc32-v2 v0.0.4 (/home/mahmoud/Desktop/TODO/crc32-v2) |
| 64 | + Finished `bench` profile [optimized] target(s) in 2.06s |
| 65 | + Running unittests src/lib.rs (target/release/deps/crc32_v2-3c56bd9cac40bc4d) |
| 66 | + |
| 67 | +running 0 tests |
| 68 | + |
| 69 | +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s |
| 70 | + |
| 71 | + Running benches/benchmark.rs (target/release/deps/benchmark-f87f05a33c0b9723) |
| 72 | +Benchmarking `crc32-v2` crc32_while_loop(0, b"hello") performance:: Warming up fBenchmarking `crc32-v2` crc32_while_loop(0, b"hello") performance:: Collecting 1`crc32-v2` crc32_while_loop(0, b"hello") performance: |
| 73 | + time: [6.6916 ns 6.7111 ns 6.7306 ns] |
| 74 | + change: [-6.2932% -5.1894% -3.8925%] (p = 0.00 < 0.05) |
| 75 | + Performance has improved. |
| 76 | +Found 14 outliers among 100 measurements (14.00%) |
| 77 | + 7 (7.00%) low mild |
| 78 | + 2 (2.00%) high mild |
| 79 | + 5 (5.00%) high severe |
| 80 | + |
| 81 | +Benchmarking `crc32-v2` crc32_for_loop(0, b"hello") performance:: Warming up forBenchmarking `crc32-v2` crc32_for_loop(0, b"hello") performance:: Collecting 100`crc32-v2` crc32_for_loop(0, b"hello") performance: |
| 82 | + time: [6.7552 ns 6.7719 ns 6.7884 ns] |
| 83 | + change: [-16.025% -12.793% -9.5779%] (p = 0.00 < 0.05) |
| 84 | + Performance has improved. |
| 85 | +Found 4 outliers among 100 measurements (4.00%) |
| 86 | + 1 (1.00%) high mild |
| 87 | + 3 (3.00%) high severe |
| 88 | + |
| 89 | +Benchmarking `crc32fast` crc32fast::hash(b"hello") performance:: Warming up for Benchmarking `crc32fast` crc32fast::hash(b"hello") performance:: Collecting 100 `crc32fast` crc32fast::hash(b"hello") performance: |
| 90 | + time: [8.4118 ns 8.4320 ns 8.4522 ns] |
| 91 | + change: [-9.0567% -7.0970% -5.3253%] (p = 0.00 < 0.05) |
| 92 | + Performance has improved. |
| 93 | +Found 4 outliers among 100 measurements (4.00%) |
| 94 | + 4 (4.00%) high severe |
| 95 | + |
| 96 | +Benchmarking `crc32fast` crc32fast::Hasher::new().update(b"hello").finalize() peBenchmarking `crc32fast` crc32fast::Hasher::new().update(b"hello").finalize() peBenchmarking `crc32fast` crc32fast::Hasher::new().update(b"hello").finalize() peBenchmarking `crc32fast` crc32fast::Hasher::new().update(b"hello").finalize() pe`crc32fast` crc32fast::Hasher::new().update(b"hello").finalize() performance: |
| 97 | + time: [21.334 ns 21.379 ns 21.419 ns] |
| 98 | + change: [-6.8627% -5.2041% -3.7228%] (p = 0.00 < 0.05) |
| 99 | + Performance has improved. |
| 100 | +Found 5 outliers among 100 measurements (5.00%) |
| 101 | + 2 (2.00%) high mild |
| 102 | + 3 (3.00%) high severe |
| 103 | +``` |
| 104 | + |
| 105 | +</details> |
| 106 | + |
| 107 | +Below is a summarized table of results, highlighting the execution times for each method: |
| 108 | + |
| 109 | +| **Method** | **Mean Time (ns)** | **Outliers (%)** | **Description** | |
| 110 | +|-----------------------------------------------|---------------------|-------------------|------------------------------------------------| |
| 111 | +| `crc32_v2_while_loop(0, b"hello")` | 6.71 | 14.00% | CRC32-V2 built-in function using a while loop, optimized. | |
| 112 | +| `crc32_v2_for_loop(0, b"hello")` | 6.77 | 4.00% | Custom CRC32-V2 using a for loop, optimized. | |
| 113 | +| `crc32fast::hash(b"hello")` | 8.43 | 4.00% | crc32fast built-in hashing method. | |
| 114 | +| `crc32fast::Hasher::new().update(b"hello").finalize()` | 21.38 | 5.00% | Hasher object approach, slower initialization.| |
| 115 | + |
| 116 | +1. **Fastest Method**: The built-in `crc32_v2_while_loop` implementation shows the best performance, slightly outperforming the `crc32_for_loop`. |
| 117 | +1. **crc32fast Performance**: The `crc32fast::hash` method is slightly slower than the `crc32-v2` implementation. |
| 118 | +1. **Hasher Object Method**: The `crc32fast::Hasher` object approach is significantly slower for some reason. |
0 commit comments