Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2019-12-10 15:32:25 -0500
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-02-24 14:56:28 -0500
commit176d099fb61a49492515a0fd35fc19b4f2b70ce9 (patch)
tree3503ce3f2cf27aaf26fcc5cb533b251aa4f96e34 /tamer/benches/sym.rs
parent0d2bb5de598019bf203ac9e151031f11df98550d (diff)
downloadtame-176d099fb61a49492515a0fd35fc19b4f2b70ce9.tar.gz
tame-176d099fb61a49492515a0fd35fc19b4f2b70ce9.tar.bz2
tame-176d099fb61a49492515a0fd35fc19b4f2b70ce9.zip
tamer::sym: FNV => Fx Hash
For strings of any notable length, Fx Hash outperforms FNV. Rustc also moved to this hash function and noticed performance improvements. Fortunately, as was accounted for in the design, this was a trivial switch. Here are some benchmarks to back up that claim: test hash_set::fnv::with_all_new_1000 ... bench: 133,096 ns/iter (+/- 1,430) test hash_set::fnv::with_all_new_1000_with_capacity ... bench: 82,591 ns/iter (+/- 592) test hash_set::fnv::with_all_new_rc_str_1000_baseline ... bench: 162,073 ns/iter (+/- 1,277) test hash_set::fnv::with_one_new_1000 ... bench: 37,334 ns/iter (+/- 256) test hash_set::fnv::with_one_new_rc_str_1000_baseline ... bench: 18,263 ns/iter (+/- 261) test hash_set::fx::with_all_new_1000 ... bench: 85,217 ns/iter (+/- 1,111) test hash_set::fx::with_all_new_1000_with_capacity ... bench: 59,383 ns/iter (+/- 752) test hash_set::fx::with_all_new_rc_str_1000_baseline ... bench: 98,802 ns/iter (+/- 1,117) test hash_set::fx::with_one_new_1000 ... bench: 42,484 ns/iter (+/- 1,239) test hash_set::fx::with_one_new_rc_str_1000_baseline ... bench: 15,000 ns/iter (+/- 233) test hash_set::with_all_new_1000 ... bench: 137,645 ns/iter (+/- 1,186) test hash_set::with_all_new_rc_str_1000_baseline ... bench: 163,129 ns/iter (+/- 1,725) test hash_set::with_one_new_1000 ... bench: 59,051 ns/iter (+/- 1,202) test hash_set::with_one_new_rc_str_1000_baseline ... bench: 37,986 ns/iter (+/- 771)
Diffstat (limited to 'tamer/benches/sym.rs')
-rw-r--r--tamer/benches/sym.rs36
1 files changed, 17 insertions, 19 deletions
diff --git a/tamer/benches/sym.rs b/tamer/benches/sym.rs
index f601bbe..9031f11 100644
--- a/tamer/benches/sym.rs
+++ b/tamer/benches/sym.rs
@@ -159,16 +159,16 @@ mod hash_set {
});
}
- mod fnv {
+ mod fx {
use super::*;
- use ::fnv::FnvBuildHasher;
+ use fxhash::FxBuildHasher;
/// This is our baseline with a raw Rc<str>.
#[bench]
fn with_all_new_rc_str_1000_baseline(bench: &mut Bencher) {
let strs = gen_strs(1000);
bench.iter(|| {
- let mut sut = HashSetSut::<FnvBuildHasher>::new();
+ let mut sut = HashSetSut::<FxBuildHasher>::new();
strs.iter().map(|s| sut.intern(&s)).for_each(drop);
});
}
@@ -178,8 +178,7 @@ mod hash_set {
let strs = gen_strs(1000);
bench.iter(|| {
- let mut sut =
- HashSetInterner::<SymbolRc, FnvBuildHasher>::new();
+ let mut sut = HashSetInterner::<SymbolRc, FxBuildHasher>::new();
strs.iter().map(|s| sut.intern(&s)).for_each(drop);
});
}
@@ -188,7 +187,7 @@ mod hash_set {
/// This is our baseline with a raw Rc<str>.
fn with_one_new_rc_str_1000_baseline(bench: &mut Bencher) {
bench.iter(|| {
- let mut sut: HashSetSut<FnvBuildHasher> = HashSetSut {
+ let mut sut: HashSetSut<FxBuildHasher> = HashSetSut {
map: HashSet::with_hasher(Default::default()),
};
(0..1000).map(|_| sut.intern("first")).for_each(drop);
@@ -198,13 +197,12 @@ mod hash_set {
#[bench]
fn with_one_new_1000(bench: &mut Bencher) {
bench.iter(|| {
- let mut sut =
- HashSetInterner::<SymbolRc, FnvBuildHasher>::new();
+ let mut sut = HashSetInterner::<SymbolRc, FxBuildHasher>::new();
(0..1000).map(|_| sut.intern("first")).for_each(drop);
});
}
- /// Since FNV is the best-performing, let's build upon it to demonstrate
+ /// Since Fx is the best-performing, let's build upon it to demonstrate
/// the benefits of with_capacity
#[bench]
fn with_all_new_1000_with_capacity(bench: &mut Bencher) {
@@ -213,7 +211,7 @@ mod hash_set {
bench.iter(|| {
let mut sut =
- HashSetInterner::<SymbolRc, FnvBuildHasher>::with_capacity(
+ HashSetInterner::<SymbolRc, FxBuildHasher>::with_capacity(
n,
);
strs.iter().map(|s| sut.intern(&s)).for_each(drop);
@@ -298,16 +296,16 @@ mod hash_map {
});
}
- mod fnv {
+ mod fx {
use super::*;
- use ::fnv::FnvBuildHasher;
+ use fxhash::FxBuildHasher;
/// This is our baseline with a raw Rc<str>.
#[bench]
fn with_all_new_rc_str_1000_baseline(bench: &mut Bencher) {
let strs = gen_strs(1000);
bench.iter(|| {
- let mut sut = HashMapSut::<(), FnvBuildHasher>::new();
+ let mut sut = HashMapSut::<(), FxBuildHasher>::new();
strs.iter().map(|s| sut.intern(&s)).for_each(drop);
});
}
@@ -318,7 +316,7 @@ mod hash_map {
bench.iter(|| {
let mut sut =
- HashMapInterner::<SymbolRc, (), FnvBuildHasher>::new();
+ HashMapInterner::<SymbolRc, (), FxBuildHasher>::new();
strs.iter().map(|s| sut.intern(&s)).for_each(drop);
});
}
@@ -327,7 +325,7 @@ mod hash_map {
/// This is our baseline with a raw Rc<str>.
fn with_one_new_rc_str_1000_baseline(bench: &mut Bencher) {
bench.iter(|| {
- let mut sut: HashMapSut<(), FnvBuildHasher> = HashMapSut {
+ let mut sut: HashMapSut<(), FxBuildHasher> = HashMapSut {
map: HashMap::with_hasher(Default::default()),
};
(0..1000).map(|_| sut.intern("first")).for_each(drop);
@@ -338,7 +336,7 @@ mod hash_map {
fn with_one_new_1000(bench: &mut Bencher) {
bench.iter(|| {
let mut sut =
- HashMapInterner::<SymbolRc, (), FnvBuildHasher>::new();
+ HashMapInterner::<SymbolRc, (), FxBuildHasher>::new();
(0..1000).map(|_| sut.intern("first")).for_each(drop);
});
}
@@ -352,7 +350,7 @@ mod hash_map {
bench.iter(|| {
let mut sut =
- HashMapInterner::<SymbolRc, (), FnvBuildHasher>::with_capacity(n);
+ HashMapInterner::<SymbolRc, (), FxBuildHasher>::with_capacity(n);
strs.iter().map(|s| sut.intern(&s)).for_each(drop);
});
}
@@ -363,7 +361,7 @@ mod hash_map {
bench.iter(|| {
let mut sut =
- HashMapInterner::<SymbolRc, u8, FnvBuildHasher>::new();
+ HashMapInterner::<SymbolRc, u8, FxBuildHasher>::new();
strs.iter().map(|s| sut.intern_meta(&s, 0)).for_each(drop);
});
}
@@ -374,7 +372,7 @@ mod hash_map {
bench.iter(|| {
let mut sut =
- HashMapInterner::<SymbolRc, u8, FnvBuildHasher>::new();
+ HashMapInterner::<SymbolRc, u8, FxBuildHasher>::new();
strs.iter()
.map(|s| {
sut.intern(&s);