use criterion::*;
use libdd_profiling::collections::string_table::wordpress_test_data::WORDPRESS_STRINGS;
#[allow(unused)]
mod old_version {
use libdd_profiling::collections::identifiable::{FxIndexSet, Id, StringId};
pub struct StringTable {
strings: FxIndexSet<Box<str>>,
}
impl StringTable {
pub fn new() -> Self {
let mut strings = FxIndexSet::<Box<str>>::default();
strings.insert("".into());
Self { strings }
}
pub fn intern(&mut self, item: &str) -> StringId {
let index = match self.strings.get_index_of(item) {
Some(index) => index,
None => {
let (index, _inserted) = self.strings.insert_full(item.into());
debug_assert!(_inserted);
index
}
};
StringId::from_offset(index)
}
#[inline]
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize {
self.strings.len()
}
}
}
use libdd_profiling::collections::string_table::StringTable;
pub fn small_wordpress_profile(c: &mut Criterion) {
c.bench_function("benching string interning on wordpress profile", |b| {
b.iter(|| {
let mut table = StringTable::new();
let n_strings = WORDPRESS_STRINGS.len();
for string in WORDPRESS_STRINGS {
black_box(table.intern(string));
}
assert_eq!(n_strings, table.len());
for string in WORDPRESS_STRINGS {
black_box(table.intern(string));
}
assert_eq!(n_strings, table.len())
})
});
}
criterion_group!(benches, small_wordpress_profile);