README.md
1<h1 align="center">simd-adler32</h1>
2<p align="center">
3 <a href="https://docs.rs/simd-adler32">
4 <img alt="docs.rs badge" src="https://img.shields.io/docsrs/simd-adler32?style=flat-square">
5 </a>
6 <a href="https://crates.io/crates/simd-adler32">
7 <img alt="crates.io badge" src="https://img.shields.io/crates/v/simd-adler32?style=flat-square">
8 </a>
9 <a href="https://github.com/mcountryman/simd-adler32/blob/main/LICENSE.md">
10 <img alt="mit license badge" src="https://img.shields.io/github/license/mcountryman/simd-adler32?style=flat-square">
11 </a>
12</p>
13
14A SIMD-accelerated Adler-32 hash algorithm implementation.
15
16## Features
17
18- No dependencies
19- Support `no_std` (with `default-features = false`)
20- Runtime CPU feature detection (when `std` enabled)
21- Blazing fast performance on as many targets as possible (currently only x86 and x86_64)
22- Default to scalar implementation when simd not available
23
24## Quick start
25
26> Cargo.toml
27
28```toml
29[dependencies]
30simd-adler32 = "*"
31```
32
33> example.rs
34
35```rust
36use simd_adler32::Adler32;
37
38let mut adler = Adler32::new();
39adler.write(b"rust is pretty cool, man");
40let hash = adler.finish();
41
42println!("{}", hash);
43// 1921255656
44```
45
46## Support
47
48**CPU Features**
49
50| impl | arch | feature |
51| ---- | ---------------- | ------- |
52| ✅ | `x86`, `x86_64` | avx512 |
53| ✅ | `x86`, `x86_64` | avx2 |
54| ✅ | `x86`, `x86_64` | ssse3 |
55| ✅ | `x86`, `x86_64` | sse2 |
56| | `arm`, `aarch64` | neon |
57| ✅ | `wasm32` | simd128 |
58
59**MSRV** `1.36.0`\*\*
60
61Minimum supported rust version is tested before a new version is published. [**] Feature
62`const-generics` needs to disabled to build on rustc versions `<1.51` which can be done
63by updating your dependency definition to the following.
64
65> Cargo.toml
66
67```toml
68[dependencies]
69simd-adler32 = { version "*", default-features = false, features = ["std"] }
70```
71
72## Performance
73
74Benchmarks listed display number of randomly generated bytes (10k / 100k) and library
75name. Benchmarks sources can be found under the [bench](/bench) directory. Crates used for
76comparison are [adler](https://crates.io/crates/adler) and
77[adler32](https://crates.io/crates/adler32).
78
79> Windows 10 Pro - Intel i5-8300H @ 2.30GHz
80
81| name | avg. time | avg. thrpt |
82| ----------------------- | --------------- | ------------------ |
83| **10k/simd-adler32** | **212.61 ns** | **43.805 GiB/s** |
84| 10k/wuffs | 3843 ns | 2.63 GiB/s\* |
85| 10k/adler32 | 4.8084 us | 1.9369 GiB/s |
86| 10k/adler | 17.979 us | 530.43 MiB/s |
87| ----------------------- | --------------- | ------------------ |
88| **100k/simd-adler32** | **2.7951 us** | **33.320 GiB/s** |
89| 100k/wuffs | 34733 ns | 2.6814 GiB/s\* |
90| 100k/adler32 | 48.488 us | 1.9207 GiB/s |
91| 100k/adler | 178.36 us | 534.69 MiB/s |
92
93\* wuffs ran using mingw64/gcc, ran with `wuffs bench -ccompilers=gcc -reps=1 -iterscale=300 std/adler32`.
94
95> MacBookPro16,1 - Intel i9-9880H CPU @ 2.30GHz
96
97| name | avg. time | avg. thrpt |
98| ----------------------- | --------------- | ------------------ |
99| **10k/simd-adler32** | **200.37 ns** | **46.480 GiB/s** |
100| 10k/adler32 | 4.1516 us | 2.2433 GiB/s |
101| 10k/adler | 10.220 us | 933.15 MiB/s |
102| ----------------------- | --------------- | ------------------ |
103| **100k/simd-adler32** | **2.3282 us** | **40.003 GiB/s** |
104| 100k/adler32 | 41.130 us | 2.2643 GiB/s |
105| 100k/adler | 83.776 us | 534.69 MiB/s |
106
107## Safety
108
109This crate contains a significant amount of `unsafe` code due to the requirement of `unsafe`
110for simd intrinsics. Fuzzing is done on release and debug builds prior to publishing via
111`afl`. Fuzzy tests can be found under [fuzz](/fuzz) the directory.
112
113## Resources
114
115- [LICENSE](./LICENSE.md) - MIT
116- [CHANGELOG](./CHANGELOG.md)
117
118## Credits
119
120Thank you to the contributors of the following projects.
121
122- [adler](https://github.com/jonas-schievink/adler)
123- [adler32](https://github.com/remram44/adler32-rs)
124- [crc32fast](https://github.com/srijs/rust-crc32fast)
125- [wuffs](https://github.com/google/wuffs)
126- [chromium](https://bugs.chromium.org/p/chromium/issues/detail?id=762564)
127- [zlib](https://zlib.net/)
128
129## Contributing
130
131Feel free to submit a issue or pull request. :smile:
132