#![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, E, F, G, H); // 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>; type R2E = RoleE>; type R2F = RoleF>; type R2G = RoleG>; type R2H = RoleH>; // A enum Branching0fromHtoA { More( MeshedChannels< RS, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursAtoH>>, R2H>>>>>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoH = Recv; // B enum Branching0fromHtoB { More( MeshedChannels< SR, RS, RS, RS, RS, RS, Recv<(), Send<(), RecursBtoH>>, R2H>>>>>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoH = Recv; // C enum Branching0fromHtoC { More( MeshedChannels< SR, SR, RS, RS, RS, RS, Recv<(), Send<(), RecursCtoH>>, R2H>>>>>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoH = Recv; // D enum Branching0fromHtoD { More( MeshedChannels< SR, SR, SR, RS, RS, RS, Recv<(), Send<(), RecursDtoH>>, R2H>>>>>>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoH = Recv; // E enum Branching0fromHtoE { More( MeshedChannels< SR, SR, SR, SR, RS, RS, Recv<(), Send<(), RecursEtoH>>, R2H>>>>>>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoH = Recv; // F enum Branching0fromHtoF { More( MeshedChannels< SR, SR, SR, SR, SR, RS, Recv<(), Send<(), RecursFtoH>>, R2H>>>>>>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoH = Recv; // G enum Branching0fromHtoG { More( MeshedChannels< SR, SR, SR, SR, SR, SR, Recv<(), Send<(), RecursGtoH>>, R2H>>>>>>>, NameG, >, ), Done(MeshedChannels), } type RecursGtoH = Recv; // H type Choose0fromHtoA = Send; type Choose0fromHtoB = Send; type Choose0fromHtoC = Send; type Choose0fromHtoD = Send; type Choose0fromHtoE = Send; type Choose0fromHtoF = Send; type Choose0fromHtoG = Send; type EndpointMoreH = MeshedChannels< Send<(), Recv<(), Choose0fromHtoA>>, Send<(), Recv<(), Choose0fromHtoB>>, Send<(), Recv<(), Choose0fromHtoC>>, Send<(), Recv<(), Choose0fromHtoD>>, Send<(), Recv<(), Choose0fromHtoE>>, Send<(), Recv<(), Choose0fromHtoF>>, Send<(), Recv<(), Choose0fromHtoG>>, R2A>>>>>>, NameH, >; // Creating the MP sessions type EndpointA = MeshedChannels, NameA>; type EndpointB = MeshedChannels, NameB>; type EndpointC = MeshedChannels, NameC>; type EndpointD = MeshedChannels, NameD>; type EndpointE = MeshedChannels, NameE>; type EndpointF = MeshedChannels, NameF>; type EndpointG = MeshedChannels, NameG>; type EndpointH = MeshedChannels< Choose0fromHtoA, Choose0fromHtoB, Choose0fromHtoC, Choose0fromHtoD, Choose0fromHtoE, Choose0fromHtoF, Choose0fromHtoG, RoleBroadcast, NameH, >; fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoA::Done(s) => { s.close() }, Branching0fromHtoA::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(())?; let (_, s) = s.recv()?; let s = s.send(())?; 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, { Branching0fromHtoB::Done(s) => { s.close() }, Branching0fromHtoB::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(())?; let (_, s) = s.recv()?; let s = s.send(())?; 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_b(s) }, }) } fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoC::Done(s) => { s.close() }, Branching0fromHtoC::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()?; let (_, s) = s.recv()?; let s = s.send(())?; 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_c(s) }, }) } fn endpoint_d(s: EndpointD) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoD::Done(s) => { s.close() }, Branching0fromHtoD::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()?; let s = s.send(())?; let (_, s) = s.recv()?; 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_d(s) }, }) } fn endpoint_e(s: EndpointE) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoE::Done(s) => { s.close() }, Branching0fromHtoE::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()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_e(s) }, }) } fn endpoint_f(s: EndpointF) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoF::Done(s) => { s.close() }, Branching0fromHtoF::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()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let (_, s) = s.recv()?; let s = s.send(())?; endpoint_f(s) }, }) } fn endpoint_g(s: EndpointG) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoG::Done(s) => { s.close() }, Branching0fromHtoG::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()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; let s = s.send(())?; let (_, s) = s.recv()?; endpoint_g(s) }, }) } fn endpoint_h(s: EndpointH) -> Result<(), Box> { recurs_h(s, LOOPS) } fn recurs_h(s: EndpointH, index: i64) -> Result<(), Box> { match index { 0 => { let s = choose_mpst_h_to_all!( s, Branching0fromHtoA::Done, Branching0fromHtoB::Done, Branching0fromHtoC::Done, Branching0fromHtoD::Done, Branching0fromHtoE::Done, Branching0fromHtoF::Done, Branching0fromHtoG::Done ); s.close() } i => { let s: EndpointMoreH = choose_mpst_h_to_all!( s, Branching0fromHtoA::More, Branching0fromHtoB::More, Branching0fromHtoC::More, Branching0fromHtoD::More, Branching0fromHtoE::More, Branching0fromHtoF::More, Branching0fromHtoG::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()?; let s = s.send(())?; let (_, s) = s.recv()?; 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_h(s, i - 1) } } } fn aux() { let (thread_a, thread_b, thread_c, thread_d, thread_e, thread_f, thread_g, thread_h) = fork_mpst( black_box(endpoint_a), black_box(endpoint_b), black_box(endpoint_c), black_box(endpoint_d), black_box(endpoint_e), black_box(endpoint_f), black_box(endpoint_g), black_box(endpoint_h), ); thread_a.join().unwrap(); thread_b.join().unwrap(); thread_c.join().unwrap(); thread_d.join().unwrap(); thread_e.join().unwrap(); thread_f.join().unwrap(); thread_g.join().unwrap(); thread_h.join().unwrap(); } ///////////////////////// static LOOPS: i64 = 100; pub fn mesh(c: &mut Criterion) { c.bench_function(&format!("mesh eight baking AMPST {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 }