Skip to content

Commit

Permalink
Minor benchmark suite cleanups (tokio-rs#363)
Browse files Browse the repository at this point in the history
* Cleanup varint benchmarks

* fix benchmarks

* workaround for windows CI
  • Loading branch information
danburkert authored Nov 9, 2020
1 parent 6c8c69e commit 1577e83
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
profile: minimal
components: clippy
- name: install ninja
uses: seanmiddleditch/gha-setup-ninja@v1
uses: seanmiddleditch/gha-setup-ninja@v3
- name: clippy
uses: actions-rs/clippy-check@v1
with:
Expand Down
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ keywords = ["protobuf", "serialization"]
categories = ["encoding"]
edition = "2018"

[badges]
travis-ci = { repository = "danburkert/prost" }
appveyor = { repository = "danburkert/prost" }

[workspace]
members = [
"conformance",
Expand Down
9 changes: 4 additions & 5 deletions benches/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ fn benchmark_varint(criterion: &mut Criterion, name: &str, mut values: Vec<u64>)
})
.throughput(Throughput::Bytes(encoded_len));

let mut decode_values = values.clone();
let decode_values = values.clone();
let decode = Benchmark::new("decode", move |b| {
let mut buf = Vec::with_capacity(decode_values.len() * 10);
for &value in &decode_values {
encode_varint(value, &mut buf);
}

b.iter(|| {
decode_values.clear();
let mut buf = &mut buf.as_slice();
while buf.has_remaining() {
let value = decode_varint(&mut buf).unwrap();
decode_values.push(value);
let result = decode_varint(&mut buf);
debug_assert!(result.is_ok());
criterion::black_box(&result);
}
criterion::black_box(&decode_values);
})
})
.throughput(Throughput::Bytes(decoded_len));
Expand Down
2 changes: 1 addition & 1 deletion protobuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ prost-types = { path = "../prost-types" }

[build-dependencies]
anyhow = "1"
cfg-if = "0.1"
# curl 0.4.34 requires Rust 1.40 or higher:
# https://github.com/alexcrichton/curl-rust/pull/356/files#r498918694
curl = "0.4, < 0.4.34"
Expand All @@ -23,6 +22,7 @@ tempfile = "3"

[dev-dependencies]
criterion = "0.3"
cfg-if = "0.1"

[lib]
# https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
Expand Down
41 changes: 22 additions & 19 deletions protobuf/benches/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use std::fs::File;
use std::io::Read;
use std::path::Path;

use cfg_if::cfg_if;
use criterion::{criterion_group, criterion_main, Criterion};
use prost::Message;

use protobuf::benchmarks::{
dataset, google_message3::GoogleMessage3, /*google_message4::GoogleMessage4,*/ proto2,
proto3, BenchmarkDataset,
dataset, google_message3::GoogleMessage3, google_message4::GoogleMessage4, proto2, proto3,
BenchmarkDataset,
};

fn load_dataset(dataset: &Path) -> Result<BenchmarkDataset, Box<dyn Error>> {
Expand All @@ -22,7 +23,9 @@ fn benchmark_dataset<M>(criterion: &mut Criterion, name: &str, dataset: &'static
where
M: prost::Message + Default + 'static,
{
criterion.bench_function(&format!("dataset/{}/merge", name), move |b| {
let mut group = criterion.benchmark_group(&format!("dataset/{}", name));

group.bench_function("merge", move |b| {
let dataset = load_dataset(dataset).unwrap();
let mut message = M::default();
b.iter(|| {
Expand All @@ -34,7 +37,7 @@ where
});
});

criterion.bench_function(&format!("dataset/{}/encode", name), move |b| {
group.bench_function("encode", move |b| {
let messages = load_dataset(dataset)
.unwrap()
.payload
Expand All @@ -53,7 +56,7 @@ where
});
});

criterion.bench_function(&format!("dataset/{}/encoded_len", name), move |b| {
group.bench_function("encoded_len", move |b| {
let messages = load_dataset(dataset)
.unwrap()
.payload
Expand All @@ -80,34 +83,34 @@ macro_rules! dataset {
dataset!(google_message1_proto2, proto2::GoogleMessage1);
dataset!(google_message1_proto3, proto3::GoogleMessage1);
dataset!(google_message2, proto2::GoogleMessage2);
//dataset!(google_message3_1, GoogleMessage3);
dataset!(google_message3_1, GoogleMessage3);
dataset!(google_message3_2, GoogleMessage3);
dataset!(google_message3_3, GoogleMessage3);
dataset!(google_message3_4, GoogleMessage3);
//dataset!(google_message3_5, GoogleMessage3);
//dataset!(google_message4, GoogleMessage4);
dataset!(google_message3_5, GoogleMessage3);
dataset!(google_message4, GoogleMessage4);

criterion_group!(
dataset,
google_message1_proto2,
google_message1_proto3,
google_message2,
google_message3_2,
google_message3_3,
google_message3_4,
);

criterion_group! {
name = slow;
config = Criterion::default().sample_size(10);
targets = google_message3_2, google_message3_4, google_message3_3
}

// TODO: Criterion now requires a sample_size of 10; figure out a better way to
// get these tests to run in a reasonable time.
/*
criterion_group! {
name = extra_slow;
config = Criterion::default().sample_size(10);
targets = google_message3_1, google_message3_5, google_message4
}
*/

criterion_main!(dataset, slow /*, extra_slow*/);
cfg_if! {
if #[cfg(debug_assertions)] {
// Disable 'slow' benchmarks for unoptimized test builds.
criterion_main!(dataset);
} else {
criterion_main!(dataset, slow);
}
}

0 comments on commit 1577e83

Please sign in to comment.