Debian Codegraph @

README.md

raw symbols SCIP
1 # Hamming Bitwise Fast
2
3 > A fast, zero-dependency implementation of bitwise Hamming Distance using
4 > a method amenable to auto-vectorization.
5
6 This started out as a benchmark of various bitwise Hamming distance implementations in Rust.
7 However, after finding that a simple implementation that is amenable to auto-vectorization
8 was comparable, if not faster, than other implementations, I decided to publish it as a crate.
9
10 **Note:** This is for comparing bit-vectors, _not_ for comparing strings.
11
12 ## Usage
13
14 ```rust
15 use hamming_bitwise_fast::hamming_bitwise_fast;
16
17 assert_eq!(hamming_bitwise_fast(&[0xFF; 1024], &[0xFF; 1024]), 0);
18 assert_eq!(hamming_bitwise_fast(&[0xFF; 1024], &[0x00; 1024]), 1024);
19 ```
20
21 ## Benchmarks
22
23 This uses [Criterion](https://github.com/bheisler/criterion.rs) to benchmark various Hamming distance implementations:
24
25 - The auto-vectorized implementation in this crate
26 - A naive for-loop based implementation
27 - A naive iterator based implementation
28 - [`hamming`](https://crates.io/crates/hamming) ![hamming](https://img.shields.io/crates/d/hamming)
29 - [`hamming_rs`](https://crates.io/crates/hamming_rs) ![hamming_rs](https://img.shields.io/crates/d/hamming_rs)
30 - [`simsimd`](https://crates.io/crates/simsimd) ![simsimd](https://img.shields.io/crates/d/simsimd)
31
32 ### Running the benchmark
33
34 ```sh
35 cargo bench
36 ```
37
38 Then open the `target/criterion/report/index.html` file in your browser to view the results.
39
40 ### Results
41
42 These were the results running on 3 different types of machines:
43
44 ### 2023 MacBook Pro M2 Max
45
46 ![Benchmark results](results/line-chart-macbook.svg)
47 ![Benchmark results](results/violin-chart-macbook.svg)
48
49 ### Linode 2 CPU 4GB
50
51 ![Benchmark results](results/line-chart-linode.svg)
52 ![Benchmark results](results/violin-chart-linode.svg)
53
54 ### Fly.io 2 CPU 4GB
55
56 ![Benchmark results](results/line-chart-fly.svg)
57 ![Benchmark results](results/violin-chart-fly.svg)
58
59 ## License
60
61 This project is licensed under either of the following licenses, at your option:
62
63 - [Apache License, Version 2.0](LICENSE-APACHE)
64 - [MIT License](LICENSE-MIT)
65
66 Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.