Skip to content

Commit 09f5ea4

Browse files
committed
Fix benchmark compilation
Signed-off-by: Tin Švagelj <[email protected]>
1 parent dfa3285 commit 09f5ea4

File tree

3 files changed

+44
-35
lines changed

3 files changed

+44
-35
lines changed

benches/bench.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ criterion_main!(bench_get_or_intern, bench_resolve, bench_get, bench_iter);
3939

4040
fn bench_get_or_intern_static(c: &mut Criterion) {
4141
let mut g = c.benchmark_group("get_or_intern_static");
42-
fn bench_for_backend<BB: BackendBenchmark>(g: &mut BenchmarkGroup<WallTime>) {
42+
fn bench_for_backend<'i, BB: BackendBenchmark<'i>>(g: &mut BenchmarkGroup<WallTime>) {
4343
#[rustfmt::skip]
4444
let static_strings = &[
4545
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
@@ -87,7 +87,7 @@ fn bench_get_or_intern_static(c: &mut Criterion) {
8787
fn bench_get_or_intern_fill_with_capacity(c: &mut Criterion) {
8888
let mut g = c.benchmark_group("get_or_intern/fill-empty/with_capacity");
8989
g.throughput(Throughput::Elements(BENCH_LEN_STRINGS as u64));
90-
fn bench_for_backend<BB: BackendBenchmark>(g: &mut BenchmarkGroup<WallTime>) {
90+
fn bench_for_backend<'i, BB: BackendBenchmark<'i>>(g: &mut BenchmarkGroup<WallTime>) {
9191
g.bench_with_input(
9292
BB::NAME,
9393
&(BENCH_LEN_STRINGS, BENCH_STRING_LEN),
@@ -113,7 +113,7 @@ fn bench_get_or_intern_fill_with_capacity(c: &mut Criterion) {
113113
fn bench_get_or_intern_fill(c: &mut Criterion) {
114114
let mut g = c.benchmark_group("get_or_intern/fill-empty/new");
115115
g.throughput(Throughput::Elements(BENCH_LEN_STRINGS as u64));
116-
fn bench_for_backend<BB: BackendBenchmark>(g: &mut BenchmarkGroup<WallTime>) {
116+
fn bench_for_backend<'i, BB: BackendBenchmark<'i>>(g: &mut BenchmarkGroup<WallTime>) {
117117
g.bench_with_input(
118118
BB::NAME,
119119
&(BENCH_LEN_STRINGS, BENCH_STRING_LEN),
@@ -139,7 +139,7 @@ fn bench_get_or_intern_fill(c: &mut Criterion) {
139139
fn bench_get_or_intern_already_filled(c: &mut Criterion) {
140140
let mut g = c.benchmark_group("get_or_intern/already-filled");
141141
g.throughput(Throughput::Elements(BENCH_LEN_STRINGS as u64));
142-
fn bench_for_backend<BB: BackendBenchmark>(g: &mut BenchmarkGroup<WallTime>) {
142+
fn bench_for_backend<'i, BB: BackendBenchmark<'i>>(g: &mut BenchmarkGroup<WallTime>) {
143143
g.bench_with_input(
144144
BB::NAME,
145145
&(BENCH_LEN_STRINGS, BENCH_STRING_LEN),
@@ -165,7 +165,7 @@ fn bench_get_or_intern_already_filled(c: &mut Criterion) {
165165
fn bench_resolve_already_filled(c: &mut Criterion) {
166166
let mut g = c.benchmark_group("resolve/already-filled");
167167
g.throughput(Throughput::Elements(BENCH_LEN_STRINGS as u64));
168-
fn bench_for_backend<BB: BackendBenchmark>(g: &mut BenchmarkGroup<WallTime>) {
168+
fn bench_for_backend<'i, BB: BackendBenchmark<'i>>(g: &mut BenchmarkGroup<WallTime>) {
169169
g.bench_with_input(
170170
BB::NAME,
171171
&(BENCH_LEN_STRINGS, BENCH_STRING_LEN),
@@ -191,7 +191,7 @@ fn bench_resolve_already_filled(c: &mut Criterion) {
191191
fn bench_resolve_unchecked_already_filled(c: &mut Criterion) {
192192
let mut g = c.benchmark_group("resolve_unchecked/already-filled");
193193
g.throughput(Throughput::Elements(BENCH_LEN_STRINGS as u64));
194-
fn bench_for_backend<BB: BackendBenchmark>(g: &mut BenchmarkGroup<WallTime>) {
194+
fn bench_for_backend<'i, BB: BackendBenchmark<'i>>(g: &mut BenchmarkGroup<WallTime>) {
195195
g.bench_with_input(
196196
BB::NAME,
197197
&(BENCH_LEN_STRINGS, BENCH_STRING_LEN),
@@ -220,7 +220,7 @@ fn bench_resolve_unchecked_already_filled(c: &mut Criterion) {
220220
fn bench_get_already_filled(c: &mut Criterion) {
221221
let mut g = c.benchmark_group("get/already-filled");
222222
g.throughput(Throughput::Elements(BENCH_LEN_STRINGS as u64));
223-
fn bench_for_backend<BB: BackendBenchmark>(g: &mut BenchmarkGroup<WallTime>) {
223+
fn bench_for_backend<'i, BB: BackendBenchmark<'i>>(g: &mut BenchmarkGroup<WallTime>) {
224224
g.bench_with_input(
225225
BB::NAME,
226226
&(BENCH_LEN_STRINGS, BENCH_STRING_LEN),
@@ -246,11 +246,11 @@ fn bench_get_already_filled(c: &mut Criterion) {
246246
fn bench_iter_already_filled(c: &mut Criterion) {
247247
let mut g = c.benchmark_group("iter/already-filled");
248248
g.throughput(Throughput::Elements(BENCH_LEN_STRINGS as u64));
249-
fn bench_for_backend<BB: BackendBenchmark>(g: &mut BenchmarkGroup<WallTime>)
249+
fn bench_for_backend<'i, BB: BackendBenchmark<'i>>(g: &mut BenchmarkGroup<WallTime>)
250250
where
251-
for<'a> &'a <BB as BackendBenchmark>::Backend: IntoIterator<
251+
for<'a> &'a <BB as BackendBenchmark<'i>>::Backend: IntoIterator<
252252
Item = (
253-
<<BB as BackendBenchmark>::Backend as Backend>::Symbol,
253+
<<BB as BackendBenchmark<'i>>::Backend as Backend<'i>>::Symbol,
254254
&'a str,
255255
),
256256
>,

benches/setup.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use string_interner::{
22
backend::{Backend, BucketBackend, BufferBackend, StringBackend},
3-
DefaultSymbol,
4-
StringInterner,
3+
DefaultSymbol, StringInterner,
54
};
65

76
/// Alphabet containing all characters that may be put into a benchmark string.
@@ -79,53 +78,64 @@ pub const BENCH_LEN_STRINGS: usize = 100_000;
7978
pub const BENCH_STRING_LEN: usize = 5;
8079

8180
type FxBuildHasher = fxhash::FxBuildHasher;
82-
type StringInternerWith<B> = StringInterner<B, FxBuildHasher>;
81+
type StringInternerWith<'i, B> = StringInterner<'i, B, FxBuildHasher>;
8382

84-
pub trait BackendBenchmark {
83+
pub trait BackendBenchmark<'i> {
8584
const NAME: &'static str;
86-
type Backend: Backend;
85+
type Backend: Backend<'i>;
8786

88-
fn setup() -> StringInternerWith<Self::Backend> {
87+
fn setup() -> StringInternerWith<'i, Self::Backend> {
8988
<StringInternerWith<Self::Backend>>::new()
9089
}
9190

92-
fn setup_with_capacity(cap: usize) -> StringInternerWith<Self::Backend> {
91+
fn setup_with_capacity(cap: usize) -> StringInternerWith<'i, Self::Backend> {
9392
<StringInternerWith<Self::Backend>>::with_capacity(cap)
9493
}
9594

96-
fn setup_filled(words: &[String]) -> StringInternerWith<Self::Backend> {
97-
words.iter().collect::<StringInternerWith<Self::Backend>>()
95+
fn setup_filled<I, S>(words: I) -> StringInternerWith<'i, Self::Backend>
96+
where
97+
I: IntoIterator<Item = S>,
98+
S: AsRef<str>,
99+
{
100+
words
101+
.into_iter()
102+
.map(|it| it.as_ref().to_string())
103+
.collect::<StringInternerWith<Self::Backend>>()
98104
}
99105

100-
fn setup_filled_with_ids(
101-
words: &[String],
106+
fn setup_filled_with_ids<I, S>(
107+
words: I,
102108
) -> (
103-
StringInternerWith<Self::Backend>,
104-
Vec<<Self::Backend as Backend>::Symbol>,
105-
) {
106-
let mut interner = <StringInternerWith<Self::Backend>>::new();
109+
StringInternerWith<'i, Self::Backend>,
110+
Vec<<Self::Backend as Backend<'i>>::Symbol>,
111+
)
112+
where
113+
I: IntoIterator<Item = S>,
114+
S: AsRef<str>,
115+
{
116+
let mut interner = <StringInternerWith<'i, Self::Backend>>::new();
107117
let word_ids = words
108-
.iter()
109-
.map(|word| interner.get_or_intern(word))
118+
.into_iter()
119+
.map(|word| interner.get_or_intern(word.as_ref()))
110120
.collect::<Vec<_>>();
111121
(interner, word_ids)
112122
}
113123
}
114124

115125
pub struct BenchBucket;
116-
impl BackendBenchmark for BenchBucket {
126+
impl<'i> BackendBenchmark<'i> for BenchBucket {
117127
const NAME: &'static str = "BucketBackend";
118-
type Backend = BucketBackend<DefaultSymbol>;
128+
type Backend = BucketBackend<'i, DefaultSymbol>;
119129
}
120130

121131
pub struct BenchString;
122-
impl BackendBenchmark for BenchString {
132+
impl<'i> BackendBenchmark<'i> for BenchString {
123133
const NAME: &'static str = "StringBackend";
124-
type Backend = StringBackend<DefaultSymbol>;
134+
type Backend = StringBackend<'i, DefaultSymbol>;
125135
}
126136

127137
pub struct BenchBuffer;
128-
impl BackendBenchmark for BenchBuffer {
138+
impl<'i> BackendBenchmark<'i> for BenchBuffer {
129139
const NAME: &'static str = "BufferBackend";
130-
type Backend = BufferBackend<DefaultSymbol>;
140+
type Backend = BufferBackend<'i, DefaultSymbol>;
131141
}

src/backend/buffer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use core::{mem, str};
77

88
/// An interner backend that concatenates all interned string contents into one large
99
/// buffer [`Vec`]. Unlike [`StringBackend`][crate::backend::StringBackend], string
10-
/// lengths are stored in the same buffer as strings preceeding the respective string
11-
/// data.
10+
/// lengths are stored in the same buffer as strings preceeding the respective string data.
1211
///
1312
/// ## Trade-offs
1413
/// - **Advantages:**

0 commit comments

Comments
 (0)