Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ ahash = { version = "0.8.3", default-features = false }
criterion = "0.4"
crossbeam-channel = "0.5"
crossbeam-utils = "0.8"
hash_str = { version = "0.2.0", features = [ "cache", "global" ] }
libc = "0.2"
serde_json = "1"
string-interner = "0.13"
Expand Down
54 changes: 53 additions & 1 deletion benches/creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;
use string_cache::DefaultAtom;
use string_interner::StringInterner;

use ustr::*;
use ustr::ustr;

use parking_lot::Mutex;

Expand Down Expand Up @@ -42,6 +42,58 @@ fn criterion_benchmark(c: &mut Criterion) {
});
});

let hash_str_cache = hash_str::get_cache();

let s = raft.clone();
c.bench_function("single raft hash_str global", move |b| {
b.iter(|| {
unsafe { hash_str::_clear_cache() };
for s in s.iter().cycle().take(100_000) {
black_box(hash_str_cache.intern(s));
}
});
});

let s = raft.clone();
c.bench_function("single raft hash_str local", move |b| {
b.iter(|| {
let host = hash_str::HashStrHost::new();
let mut cache = hash_str::HashStrCache::new();
for s in s.iter().cycle().take(100_000) {
black_box(cache.intern_with(&host, s));
}
});
});

let s = raft.clone();
let precomputed: Vec<_> = s.iter().map(|s| ustr(s)).collect();
c.bench_function("single raft ustr precomputed", move |b| {
let mut cache = ustr::UstrMap::default();
b.iter(|| {
cache.clear();
for &s in precomputed.iter().cycle().take(100_000) {
black_box(cache.entry(s).or_insert(s));
}
});
});

let s = raft.clone();
let precomputed_host = hash_str::HashStrHost::new();
let mut precomputed_cache = hash_str::HashStrCache::new();
let precomputed: Vec<_> = s
.iter()
.map(|s| precomputed_cache.intern_with(&precomputed_host, s))
.collect();
c.bench_function("single raft hash_str local precomputed", move |b| {
let mut cache = hash_str::HashStrCache::new();
b.iter(|| {
cache.clear();
for s in precomputed.iter().cycle().take(100_000) {
black_box(cache.cache(s));
}
});
});

let s = raft.clone();
c.bench_function("single raft string-interner", move |b| {
b.iter(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/stringcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,4 @@ impl StringCacheEntry {
std::mem::align_of::<StringCacheEntry>(),
))
}
}
}