Closed CAD97 closed 3 years ago
This is true on other systems too. the cargo-criterion runner uses a non-blocking socket in BenchTarget::execute
, and in a lot of other places just uses ?
on socket errors, which means that EWOULDBLOCK reaches the top level and panics if ever data is not available in time, and makes the whole thing very racey.
A simple workaround is to remove the code in that method that sets the listener non-blocking, though I'm not sure if there are any downsides.
I have the same problem under macOS 11.2.3, rustc/cargo 1.50.0, cargo-criterion 1.0.1, criterion 0.3.4.
It's even reproducible with a simple benchmark as this:
use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput};
use rand::RngCore;
fn int_add_benchmark(c: &mut Criterion) {
let mut rng = rand::thread_rng();
let mut group = c.benchmark_group("add");
let x = rng.next_u32();
let y = rng.next_u32();
let pair = (&x, &y);
group.bench_with_input(
BenchmarkId::new("x & y", format!("({}, {})", &x, &y)),
&pair,
|b, &(x, y)| b.iter(|| x + y),
);
group.finish();
}
criterion_group!(add_benches, int_add_benchmark,);
criterion_main!(add_benches,);
Bumping for visibility - I just ran into this on Windows installing cargo criterion
for the first time after using criterion
benchmarks for a while. The error occurs every time, including for any individual bench targeted with --bench
.
Toolchain: stable-x86_64-pc-windows-msvc
rustc
: 1.52.1 (9bc8c42bb 2021-05-09)
cargo
: 1.52.0 (69767412a 2021-04-21)
cargo-criterion
: 1.0.1
criterion
: 0.3.3
The traces I get seem to be a bit different:
Fixed in cargo-criterion-1.1.0
.
I'm not sure what happened here, I just installed cargo-criterion and did
cargo criterion
.OS: Windows
Toolchain: nightly-x86_64-pc-windows-msvc (directory override for '\?\D:\repos\cad97\playground')
rustc 1.52.0-nightly (e37a13cc3 2021-02-28)
Version: cargo-criterion 1.0.1
Criterion: 0.3.4