|
2 | 2 | mod common;
|
3 | 3 |
|
4 | 4 | use common::TestLoglogd;
|
5 |
| -use criterion::{criterion_group, criterion_main, Criterion}; |
| 5 | +use convi::ExpectFrom; |
| 6 | +use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; |
6 | 7 | use loglog::Client;
|
7 | 8 |
|
8 | 9 | fn criterion_benchmark(c: &mut Criterion) {
|
9 | 10 | let server = TestLoglogd::new().unwrap();
|
10 | 11 |
|
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()]; |
13 | 13 |
|
14 | 14 | 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 | + } |
39 | 56 | }
|
40 | 57 |
|
41 | 58 | criterion_group!(benches, criterion_benchmark);
|
|
0 commit comments