Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crossbeam-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-fea

[dev-dependencies]
fastrand = "2"
num_cpus = "1.13.0"
signal-hook = "0.4"

[lints]
Expand Down
36 changes: 22 additions & 14 deletions crossbeam-channel/benches/crossbeam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@

extern crate test;

use std::num::NonZeroUsize;

use crossbeam_channel::{bounded, unbounded};
use crossbeam_utils::thread::scope;
use test::Bencher;

const TOTAL_STEPS: usize = 40_000;

fn num_cpus() -> usize {
std::thread::available_parallelism()
.unwrap_or(NonZeroUsize::MIN)
.into()
}

mod unbounded {
use super::*;

Expand Down Expand Up @@ -36,7 +44,7 @@ mod unbounded {

#[bench]
fn par_inout(b: &mut Bencher) {
let threads = num_cpus::get();
let threads = num_cpus();
let steps = TOTAL_STEPS / threads;
let (s, r) = unbounded::<i32>();

Expand Down Expand Up @@ -99,7 +107,7 @@ mod unbounded {

#[bench]
fn spmc(b: &mut Bencher) {
let threads = num_cpus::get() - 1;
let threads = num_cpus() - 1;
let steps = TOTAL_STEPS / threads;
let (s, r) = unbounded::<i32>();

Expand Down Expand Up @@ -135,7 +143,7 @@ mod unbounded {

#[bench]
fn mpsc(b: &mut Bencher) {
let threads = num_cpus::get() - 1;
let threads = num_cpus() - 1;
let steps = TOTAL_STEPS / threads;
let (s, r) = unbounded::<i32>();

Expand Down Expand Up @@ -171,7 +179,7 @@ mod unbounded {

#[bench]
fn mpmc(b: &mut Bencher) {
let threads = num_cpus::get();
let threads = num_cpus();
let steps = TOTAL_STEPS / threads;
let (s, r) = unbounded::<i32>();

Expand Down Expand Up @@ -247,7 +255,7 @@ mod bounded_n {

#[bench]
fn spmc(b: &mut Bencher) {
let threads = num_cpus::get() - 1;
let threads = num_cpus() - 1;
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(steps * threads);

Expand Down Expand Up @@ -283,7 +291,7 @@ mod bounded_n {

#[bench]
fn mpsc(b: &mut Bencher) {
let threads = num_cpus::get() - 1;
let threads = num_cpus() - 1;
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(steps * threads);

Expand Down Expand Up @@ -319,7 +327,7 @@ mod bounded_n {

#[bench]
fn par_inout(b: &mut Bencher) {
let threads = num_cpus::get();
let threads = num_cpus();
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(threads);

Expand Down Expand Up @@ -353,7 +361,7 @@ mod bounded_n {

#[bench]
fn mpmc(b: &mut Bencher) {
let threads = num_cpus::get();
let threads = num_cpus();
assert_eq!(threads % 2, 0);
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(steps * threads);
Expand Down Expand Up @@ -444,7 +452,7 @@ mod bounded_1 {

#[bench]
fn spmc(b: &mut Bencher) {
let threads = num_cpus::get() - 1;
let threads = num_cpus() - 1;
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(1);

Expand Down Expand Up @@ -480,7 +488,7 @@ mod bounded_1 {

#[bench]
fn mpsc(b: &mut Bencher) {
let threads = num_cpus::get() - 1;
let threads = num_cpus() - 1;
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(1);

Expand Down Expand Up @@ -516,7 +524,7 @@ mod bounded_1 {

#[bench]
fn mpmc(b: &mut Bencher) {
let threads = num_cpus::get();
let threads = num_cpus();
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(1);

Expand Down Expand Up @@ -597,7 +605,7 @@ mod bounded_0 {

#[bench]
fn spmc(b: &mut Bencher) {
let threads = num_cpus::get() - 1;
let threads = num_cpus() - 1;
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(0);

Expand Down Expand Up @@ -633,7 +641,7 @@ mod bounded_0 {

#[bench]
fn mpsc(b: &mut Bencher) {
let threads = num_cpus::get() - 1;
let threads = num_cpus() - 1;
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(0);

Expand Down Expand Up @@ -669,7 +677,7 @@ mod bounded_0 {

#[bench]
fn mpmc(b: &mut Bencher) {
let threads = num_cpus::get();
let threads = num_cpus();
let steps = TOTAL_STEPS / threads;
let (s, r) = bounded::<i32>(0);

Expand Down