#![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); // 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>; // A enum Branching0fromGtoA { More( MeshedChannels< RS, RS, RS, RS, RS, Recv<(), Send<(), RecursAtoG>>, R2G>>>>>>, NameA, >, ), Done(MeshedChannels), } type RecursAtoG = Recv; // B enum Branching0fromGtoB { More( MeshedChannels< SR, RS, RS, RS, RS, Recv<(), Send<(), RecursBtoG>>, R2G>>>>>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoG = Recv; // C enum Branching0fromGtoC { More( MeshedChannels< SR, SR, RS, RS, RS, Recv<(), Send<(), RecursCtoG>>, R2G>>>>>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoG = Recv; // D enum Branching0fromGtoD { More( MeshedChannels< SR, SR, SR, RS, RS, Recv<(), Send<(), RecursDtoG>>, R2G>>>>>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoG = Recv; // E enum Branching0fromGtoE { More( MeshedChannels< SR, SR, SR, SR, RS, Recv<(), Send<(), RecursEtoG>>, R2G>>>>>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoG = Recv; // F enum Branching0fromGtoF { More( MeshedChannels< SR, SR, SR, SR, SR, Recv<(), Send<(), RecursFtoG>>, R2G>>>>>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoG = Recv; // F type Choose0fromGtoA = Send; type Choose0fromGtoB = Send; type Choose0fromGtoC = Send; type Choose0fromGtoD = Send; type Choose0fromGtoE = Send; type Choose0fromGtoF = Send; type EndpointMoreG = MeshedChannels< Send<(), Recv<(), Choose0fromGtoA>>, Send<(), Recv<(), Choose0fromGtoB>>, Send<(), Recv<(), Choose0fromGtoC>>, Send<(), Recv<(), Choose0fromGtoD>>, Send<(), Recv<(), Choose0fromGtoE>>, Send<(), Recv<(), Choose0fromGtoF>>, R2A>>>>>, NameG, >; // 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< Choose0fromGtoA, Choose0fromGtoB, Choose0fromGtoC, Choose0fromGtoD, Choose0fromGtoE, Choose0fromGtoF, RoleBroadcast, NameG, >; fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoA::Done(s) => { s.close() }, Branching0fromGtoA::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(())?; endpoint_a(s) }, }) } fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoB::Done(s) => { s.close() }, Branching0fromGtoB::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(())?; endpoint_b(s) }, }) } fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoC::Done(s) => { s.close() }, Branching0fromGtoC::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(())?; endpoint_c(s) }, }) } fn endpoint_d(s: EndpointD) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoD::Done(s) => { s.close() }, Branching0fromGtoD::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(())?; endpoint_d(s) }, }) } fn endpoint_e(s: EndpointE) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoE::Done(s) => { s.close() }, Branching0fromGtoE::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(())?; endpoint_e(s) }, }) } fn endpoint_f(s: EndpointF) -> Result<(), Box> { offer_mpst!(s, { Branching0fromGtoF::Done(s) => { s.close() }, Branching0fromGtoF::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()?; endpoint_f(s) }, }) } fn endpoint_g(s: EndpointG) -> Result<(), Box> { recurs_g(s, LOOPS) } fn recurs_g(s: EndpointG, index: i64) -> Result<(), Box> { match index { 0 => { let s = choose_mpst_g_to_all!( s, Branching0fromGtoA::Done, Branching0fromGtoB::Done, Branching0fromGtoC::Done, Branching0fromGtoD::Done, Branching0fromGtoE::Done, Branching0fromGtoF::Done ); s.close() } i => { let s: EndpointMoreG = choose_mpst_g_to_all!( s, Branching0fromGtoA::More, Branching0fromGtoB::More, Branching0fromGtoC::More, Branching0fromGtoD::More, Branching0fromGtoE::More, Branching0fromGtoF::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()?; recurs_g(s, i - 1) } } } fn aux() { let (thread_a, thread_b, thread_c, thread_d, thread_e, thread_f, thread_g) = 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), ); 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(); } ///////////////////////// static LOOPS: i64 = 100; pub fn mesh(c: &mut Criterion) { c.bench_function(&format!("mesh seven 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 }