TLDR: I'm looking for any advice on how to improve the benchmarks below so I can have confidence in the results before moving on to the next feature in this project.
I'm currently working on a tool which relies heavily on the performance of Rust's HashMap implementation in the standard library. Since reading about the cryptographic hashing algorithm used in the standard library, I've been wondering if I couldn't improve the performance of my program just by swapping out the hashing algorithm (using the unstable hashmap_hasher
feature).
The benchmarks mimic the program (which takes short 7-15 byte vectors and counts them and their positions in a source string), with the exception that instead of accumulating bytestring locations as well as counts, these benchmarks just count the instances. I hoped to do this to approximate the lookup and mutation costs of the HashMap without also mixing Vec's performance in the benchmark (because I can't affect that using different hashing algorithms).
There are several benchmarks I found which address just various hashing algorithms' speed, but I want to make sure that speed actually impacts my use case in a meaningful way, and I only wanted to benchmark those crates which already implement the std::collections::hash_state::HashState
trait.
Is this overkill? Are there any gaps in what I'm measuring? Am I accidentally benchmarking different behavior than the hashing algorithms themselves? Feedback would be very appreciated.
$ rustc --version --verbose
rustc 1.7.0-nightly (2fb0c5ebc 2016-01-14)
binary: rustc
commit-hash: 2fb0c5ebcf6d912224532265776fb96febea9797
commit-date: 2016-01-14
host: x86_64-unknown-linux-gnu
release: 1.7.0-nightly
algorithm | run 1 (ns) | run 2 (ns) | run 3 (ns) | avg (ns) | minus overhead (ns) | percent faster |
---|---|---|---|---|---|---|
crc24 | 614 | 604 | 614 | 610.7 | 378.0 | 4.5% |
default | 637 | 612 | 636 | 628.3 | 395.7 | 0.0% |
farm | 634 | 633 | 644 | 637.0 | 404.3 | -2.2% |
metro | 590 | 586 | 599 | 591.7 | 359.0 | 9.3% |
fnv | 581 | 579 | 598 | 586.0 | 353.3 | 10.7% |
twox_fixed | 612 | 614 | 620 | 615.3 | 382.7 | 3.3% |
twox_random | 611 | 614 | 623 | 616.0 | 383.3 | 3.1% |
indexing overhead | 234 | 232 | 232 | 233 |
$ for i in {1..3}; do cargo bench; done
Compiling hash-test v0.1.0 (file:///home/adam/rust-projects/hash-test)
Running target/release/hash_test-bbd6a6d5fb54cc08
running 8 tests
test bench_crc24 ... bench: 614 ns/iter (+/- 169) = 13 MB/s
test bench_default ... bench: 637 ns/iter (+/- 75) = 12 MB/s
test bench_farmhash ... bench: 634 ns/iter (+/- 112) = 12 MB/s
test bench_metrohash ... bench: 590 ns/iter (+/- 96) = 13 MB/s
test bench_random_indexes ... bench: 234 ns/iter (+/- 22)
test bench_servo_fnv ... bench: 581 ns/iter (+/- 45) = 13 MB/s
test bench_twox_fixed_seed ... bench: 612 ns/iter (+/- 24) = 13 MB/s
test bench_twox_random_seed ... bench: 611 ns/iter (+/- 30) = 13 MB/s
test result: ok. 0 passed; 0 failed; 0 ignored; 8 measured
Running target/release/hash_test-bbd6a6d5fb54cc08
running 8 tests
test bench_crc24 ... bench: 607 ns/iter (+/- 38) = 13 MB/s
test bench_default ... bench: 612 ns/iter (+/- 41) = 13 MB/s
test bench_farmhash ... bench: 633 ns/iter (+/- 63) = 12 MB/s
test bench_metrohash ... bench: 586 ns/iter (+/- 15) = 13 MB/s
test bench_random_indexes ... bench: 232 ns/iter (+/- 17)
test bench_servo_fnv ... bench: 579 ns/iter (+/- 31) = 13 MB/s
test bench_twox_fixed_seed ... bench: 614 ns/iter (+/- 50) = 13 MB/s
test bench_twox_random_seed ... bench: 614 ns/iter (+/- 31) = 13 MB/s
test result: ok. 0 passed; 0 failed; 0 ignored; 8 measured
Running target/release/hash_test-bbd6a6d5fb54cc08
running 8 tests
test bench_crc24 ... bench: 618 ns/iter (+/- 42) = 12 MB/s
test bench_default ... bench: 636 ns/iter (+/- 55) = 12 MB/s
test bench_farmhash ... bench: 644 ns/iter (+/- 42) = 12 MB/s
test bench_metrohash ... bench: 599 ns/iter (+/- 55) = 13 MB/s
test bench_random_indexes ... bench: 232 ns/iter (+/- 11)
test bench_servo_fnv ... bench: 598 ns/iter (+/- 63) = 13 MB/s
test bench_twox_fixed_seed ... bench: 620 ns/iter (+/- 34) = 12 MB/s
test bench_twox_random_seed ... bench: 623 ns/iter (+/- 38) = 12 MB/s
test result: ok. 0 passed; 0 failed; 0 ignored; 8 measured