You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I wanted to benchmark a number of ways to lookup a word in a list (or set) of words.
Each benchmark consists of looking up 4 words which are not part of the list, and one word which is. There are two lists of words: one of 35 and a second of 85 words.
Surprisingly, the PHF benchmarks are slower than the benchmarks which include setting up a mutual hash.
As the PHF hash is setup outside of the benchmark, I expected it to be faster then the hash which has to be created within the benchmark.
test tests::bench_35_words_hashmap_mutable ... bench: 58 ns/iter (+/- 1)
test tests::bench_35_words_hashmap_static_phf ... bench: 69 ns/iter (+/- 1)
test tests::bench_85_words_hashmap_mutable ... bench: 58 ns/iter (+/- 2)
test tests::bench_85_words_hashmap_static_phf ... bench: 70 ns/iter (+/- 2)
Two benchmark functions look like
#[bench]
fn bench_35_words_hashmap_static_phf(b: &mut Bencher) {
b.iter(|| {
let no = &PHF_HASH_35.contains_key(&"foo1"); assert!(! no);
let no = &PHF_HASH_35.contains_key(&"foo2"); assert!(! no);
let no = &PHF_HASH_35.contains_key(&"foo3"); assert!(! no);
let no = &PHF_HASH_35.contains_key(&"foo4"); assert!(! no);
let yes = &PHF_HASH_35.contains_key(&"tsconfig.json"); assert!(yes);
})
}
#[bench]
fn bench_85_words_hashmap_mutable(b: &mut Bencher) {
use std::collections::HashMap;
let mut choiceshash = HashMap::new();
for val in &CHOICES85 {
choiceshash.insert(val, 1);
}
b.iter(|| {
let no = &choiceshash.contains_key(&"foo1"); assert!(! no);
let no = &choiceshash.contains_key(&"foo2"); assert!(! no);
let no = &choiceshash.contains_key(&"foo3"); assert!(! no);
let no = &choiceshash.contains_key(&"foo4"); assert!(! no);
let yes = &choiceshash.contains_key(&"tsconfig.json"); assert!(yes);
})
}
I cannot find an error, but this is the first time I wrote a benchmark or used PHF (and the second time I wrote a Rust program)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I wanted to benchmark a number of ways to lookup a word in a list (or set) of words.
Each benchmark consists of looking up 4 words which are not part of the list, and one word which is. There are two lists of words: one of 35 and a second of 85 words.
Surprisingly, the PHF benchmarks are slower than the benchmarks which include setting up a mutual hash.
As the PHF hash is setup outside of the benchmark, I expected it to be faster then the hash which has to be created within the benchmark.
Two benchmark functions look like
I cannot find an error, but this is the first time I wrote a benchmark or used PHF (and the second time I wrote a Rust program)
Could you please have a look?
The repo is https://github.com/marbx/LearnRust/tree/main/BenchmarkContainsBinarySearch
Beta Was this translation helpful? Give feedback.
All reactions