#![allow( clippy::large_enum_variant, clippy::type_complexity, clippy::too_many_arguments )] use criterion::{black_box, criterion_group, criterion_main, Criterion}; use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send}; use mpstthree::generate; use mpstthree::role::broadcast::RoleBroadcast; use mpstthree::role::end::RoleEnd; use std::error::Error; // Create new roles generate!("rec_and_cancel", MeshedChannels, A, B, C, D); // Types // Send/Recv type RS = Recv<(), Send<(), End>>; type SR = Send<(), Recv<(), End>>; // Roles type R2A = RoleA>; type R2B = RoleB>; type R2C = RoleC>; type R2D = RoleD>; // A enum Branching0fromDtoA { More( MeshedChannels< RS, RS, Recv<(), Send<(), RecursAtoD>>, R2D>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoD = Recv; // B enum Branching0fromDtoB { More( MeshedChannels< SR, RS, Recv<(), Send<(), RecursBtoD>>, R2D>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoD = Recv; // C enum Branching0fromDtoC { More( MeshedChannels< SR, SR, Recv<(), Send<(), RecursCtoD>>, R2D>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoD = Recv; // D type Choose0fromDtoA = Send; type Choose0fromDtoB = Send; type Choose0fromDtoC = Send; type EndpointMoreD = MeshedChannels< Send<(), Recv<(), Choose0fromDtoA>>, Send<(), Recv<(), Choose0fromDtoB>>, Send<(), Recv<(), Choose0fromDtoC>>, R2A>>, NameD, >; // Creating the MP sessions type EndpointA = MeshedChannels, NameA>; type EndpointB = MeshedChannels, NameB>; type EndpointC = MeshedChannels, NameC>; type EndpointD = MeshedChannels; fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromDtoA::Done(s) => { s.close() }, Branching0fromDtoA::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_a(s) }, }) } #[inline] fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromDtoB::Done(s) => { s.close() }, Branching0fromDtoB::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let s = s.send(())?; let (_, s) = s.recv()?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_b(s) }, }) } #[inline] fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromDtoC::Done(s) => { s.close() }, Branching0fromDtoC::More(s) => { let (_, s) = s.recv()?; let s = s.send(())?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; endpoint_c(s) }, }) } #[inline] fn endpoint_d(s: EndpointD) -> Result<(), Box> { let mut temp_s = s; for _ in 1..LOOPS { temp_s = recurs_d(temp_s)?; } let s = choose_mpst_d_to_all!( temp_s, Branching0fromDtoA::Done, Branching0fromDtoB::Done, Branching0fromDtoC::Done ); s.close() } fn recurs_d(s: EndpointD) -> Result> { let s: EndpointMoreD = choose_mpst_d_to_all!( s, Branching0fromDtoA::More, Branching0fromDtoB::More, Branching0fromDtoC::More ); let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; Ok(s) } fn aux() { let (thread_a, thread_b, thread_c, thread_d) = fork_mpst( black_box(endpoint_a), black_box(endpoint_b), black_box(endpoint_c), black_box(endpoint_d), ); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); thread_d.join().unwrap(); } ///////////////////////// static LOOPS: i64 = 100; pub fn mesh(c: &mut Criterion) { c.bench_function(&format!("mesh four baking inline {LOOPS}"), |b| b.iter(aux)); } ///////////////////////// criterion_group! { name = bench; config = Criterion::default().significance_level(0.05).without_plots().sample_size(100000); targets = mesh, } criterion_main! { bench }