3 ms·
Small speed note: Rust 1.7 just made custom hashing functions available. Rust uses a cryptographically secure hashing function by default, but for work like thi
by steveklabnik 11y ago
Small speed note: Rust 1.7 just made custom hashing functions available. Rust uses a cryptographically secure hashing function by default, but for work like this, that's inappropriate. To use FNV instead:
1. add fnv to your Cargo.toml's dependencies section
2. The first few lines become:
extern crate fnv;
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use fnv::FnvHasher;
type MyHasher = BuildHasherDefault<FnvHasher>;
2. and the hash creation line becomes
let mut last_digit_pair_counts: HashMap<String, u64, MyHasher> = HashMap::default();
This is 17% faster on my two runs of your code. :)
Other notes:
format!("{}-{}", last_digit0, last_digit1).to_string();
The .to_string() is redundant here, format! already gives you a String. That should remove a bunch of allocations.
- chucksmash 11y agoThanks for taking time to give pointers to a noob Rustacean - this made my day.
- steveklabnik 11y agoAny time :) Oh, one other thing: I noticed you said 20 seconds. Mine took about 4 seconds, and I was wondering where the difference was... did you compile with optimizations? Without, it takes 22s on my machine... `--release` as an argument to Cargo, or `-C opt-level=3` as an argument to rustc.