#![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!("recursive", 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) }, }) } 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) }, }) } 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) }, }) } fn endpoint_d(s: EndpointD) -> Result<(), Box> { recurs_d(s, LOOPS) } fn recurs_d(s: EndpointD, index: i64) -> Result<(), Box> { match index { 0 => { let s = choose_mpst_d_to_all!( s, Branching0fromDtoA::Done, Branching0fromDtoB::Done, Branching0fromDtoC::Done ); s.close() } i => { 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(); recurs_d(s, i - 1) } } } 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 MPST {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 }