Skip to content

Commit def285c

Browse files
committed
refactor: benches
1 parent 36d5a87 commit def285c

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

loglogd/benches/basic.rs

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,57 @@
22
mod common;
33

44
use common::TestLoglogd;
5-
use criterion::{criterion_group, criterion_main, Criterion};
5+
use convi::ExpectFrom;
6+
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
67
use loglog::Client;
78

89
fn criterion_benchmark(c: &mut Criterion) {
910
let server = TestLoglogd::new().unwrap();
1011

11-
let small_entry = &[1u8, 2u8, 3u8];
12-
let big_entry = &[1u8; 10000];
12+
let entries = [[1u8, 2u8, 3u8].as_slice(), [1u8; 10000].as_slice()];
1313

1414
let mut client = server.new_client().unwrap();
15-
16-
c.bench_function("small write nocommit", |b| {
17-
b.iter(|| client.append_nocommit(small_entry))
18-
});
19-
c.bench_function("big write nocommit", |b| {
20-
b.iter(|| client.append_nocommit(big_entry))
21-
});
22-
c.bench_function("small write commit", |b| {
23-
b.iter(|| client.append(small_entry))
24-
});
25-
c.bench_function("big write commit", |b| b.iter(|| client.append(big_entry)));
26-
27-
c.bench_function("small roundtrip", |b| {
28-
b.iter(|| {
29-
client.append_nocommit(small_entry).unwrap();
30-
client.read().unwrap();
31-
})
32-
});
33-
c.bench_function("big roundtrip", |b| {
34-
b.iter(|| {
35-
client.append_nocommit(big_entry).unwrap();
36-
client.read().unwrap();
37-
})
38-
});
15+
{
16+
let mut write_nocommit = c.benchmark_group("write nocommit");
17+
for entry in entries {
18+
write_nocommit.throughput(criterion::Throughput::Bytes(u64::expect_from(entry.len())));
19+
write_nocommit.bench_with_input(
20+
BenchmarkId::from_parameter(entry.len()),
21+
entry,
22+
|b, entry| b.iter(|| client.append_nocommit(entry)),
23+
);
24+
}
25+
write_nocommit.finish();
26+
}
27+
{
28+
let mut write_commit = c.benchmark_group("write commit");
29+
for entry in entries {
30+
write_commit.throughput(criterion::Throughput::Bytes(u64::expect_from(entry.len())));
31+
write_commit.bench_with_input(
32+
BenchmarkId::from_parameter(entry.len()),
33+
entry,
34+
|b, entry| b.iter(|| client.append(entry)),
35+
);
36+
}
37+
write_commit.finish();
38+
}
39+
{
40+
let mut roundtrip = c.benchmark_group("roundtrip");
41+
for entry in entries {
42+
roundtrip.throughput(criterion::Throughput::Bytes(u64::expect_from(entry.len())));
43+
roundtrip.bench_with_input(
44+
BenchmarkId::from_parameter(entry.len()),
45+
entry,
46+
|b, entry| {
47+
b.iter(|| {
48+
client.append_nocommit(entry).unwrap();
49+
client.read().unwrap();
50+
})
51+
},
52+
);
53+
}
54+
roundtrip.finish();
55+
}
3956
}
4057

4158
criterion_group!(benches, criterion_benchmark);

0 commit comments

Comments
 (0)