What's wrong with this benchmark, the result is totally unexpected
```
group.bench_function("Flume (sync)", |b| {
b.iter(|| {
let (tx, rx) = flume::bounded(1024);
let producer = thread::spawn(move || {
for _ in 0..MSG_COUNT {
tx.send(0).unwrap();
}
});
let consumer = thread::spawn(move || {
for _ in 0..MSG_COUNT {
black_box(rx.recv().unwrap());
}
});
producer.join().unwrap();
consumer.join().unwrap();
});
});
group.bench_function("Std MPSC (sync)", |b| {
b.iter(|| {
let (tx, rx) = std::sync::mpsc::sync_channel(1024);
let producer = thread::spawn(move || {
for _ in 0..MSG_COUNT {
tx.send(0).unwrap();
}
});
let consumer = thread::spawn(move || {
for _ in 0..MSG_COUNT {
black_box(rx.recv().unwrap());
}
});
producer.join().unwrap();
consumer.join().unwrap();
});
});
```
test result:
```
Benchmarking Queue Throughput/Flume (sync): Collecting 1000 samples in estimated 48.6
Queue Throughput/Flume (sync)
time: [48.502 µs 48.558 µs 48.614 µs]
thrpt: [21.064 Melem/s 21.088 Melem/s 21.113 Melem/s]
change:
time: [-52.993% -52.893% -52.790%] (p = 0.00 < 0.05)
thrpt: [+111.82% +112.28% +112.73%]
Performance has improved.
Found 45 outliers among 1000 measurements (4.50%)
8 (0.80%) low severe
8 (0.80%) low mild
13 (1.30%) high mild
16 (1.60%) high severe
Benchmarking Queue Throughput/Std MPSC (sync): Collecting 1000 samples in estimated 3
Queue Throughput/Std MPSC (sync)
time: [33.888 µs 33.937 µs 33.994 µs]
thrpt: [30.123 Melem/s 30.173 Melem/s 30.218 Melem/s]
change:
time: [-65.127% -65.036% -64.938%] (p = 0.00 < 0.05)
thrpt: [+185.21% +186.00% +186.76%]
Performance has improved.
Found 77 outliers among 1000 measurements (7.70%)
7 (0.70%) low severe
22 (2.20%) low mild
35 (3.50%) high mild
13 (1.30%) high severe
```
关闭于 2025-03-26 2 条评论