#![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; generate!("rec_and_cancel", MeshedChannels, A, B, C, D, E, F, G, H); // Types // A enum Branching0fromHtoA { Forward( MeshedChannels< Send<(), End>, End, End, End, End, End, RecursAtoH, RoleB>, NameA, >, ), Backward( MeshedChannels< Recv<(), End>, End, End, End, End, End, RecursAtoH, RoleB>, NameA, >, ), Done(MeshedChannels), } type RecursAtoH = Recv; // B enum Branching0fromHtoB { Forward( MeshedChannels< Recv<(), End>, Send<(), End>, End, End, End, End, RecursBtoH, RoleA>>, NameB, >, ), Backward( MeshedChannels< Send<(), End>, Recv<(), End>, End, End, End, End, RecursBtoH, RoleC>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoH = Recv; // C enum Branching0fromHtoC { Forward( MeshedChannels< End, Recv<(), End>, Send<(), End>, End, End, End, RecursCtoH, RoleB>>, NameC, >, ), Backward( MeshedChannels< End, Send<(), End>, Recv<(), End>, End, End, End, RecursCtoH, RoleD>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoH = Recv; // D enum Branching0fromHtoD { Forward( MeshedChannels< End, End, Recv<(), End>, Send<(), End>, End, End, RecursDtoH, RoleC>>, NameD, >, ), Backward( MeshedChannels< End, End, Send<(), End>, Recv<(), End>, End, End, RecursDtoH, RoleE>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoH = Recv; // E enum Branching0fromHtoE { Forward( MeshedChannels< End, End, End, Recv<(), End>, Send<(), End>, End, RecursEtoH, RoleD>>, NameE, >, ), Backward( MeshedChannels< End, End, End, Send<(), End>, Recv<(), End>, End, RecursEtoH, RoleF>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoH = Recv; // F enum Branching0fromHtoF { Forward( MeshedChannels< End, End, End, End, Recv<(), End>, Send<(), End>, RecursFtoH, RoleE>>, NameF, >, ), Backward( MeshedChannels< End, End, End, End, Send<(), End>, Recv<(), End>, RecursFtoH, RoleG>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoH = Recv; // G enum Branching0fromHtoG { Forward( MeshedChannels< End, End, End, End, End, Recv<(), End>, Send<(), RecursGtoH>, RoleF>>, NameG, >, ), Backward( MeshedChannels< End, End, End, End, End, Send<(), End>, Recv<(), RecursGtoH>, RoleH>>, 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 EndpointForwardH = MeshedChannels< Choose0fromHtoA, Choose0fromHtoB, Choose0fromHtoC, Choose0fromHtoD, Choose0fromHtoE, Choose0fromHtoF, Recv<(), Choose0fromHtoG>, RoleG, NameH, >; type EndpointBackwardH = MeshedChannels< Choose0fromHtoA, Choose0fromHtoB, Choose0fromHtoC, Choose0fromHtoD, Choose0fromHtoE, Choose0fromHtoF, Send<(), Choose0fromHtoG>, RoleG, 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::Forward(s) => { let s = s.send(())?; endpoint_a(s) }, Branching0fromHtoA::Backward(s) => { let (_, s) = s.recv()?; endpoint_a(s) }, }) } fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromHtoB::Done(s) => { s.close() }, Branching0fromHtoB::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_b(s) }, Branching0fromHtoB::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_c(s) }, Branching0fromHtoC::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_d(s) }, Branching0fromHtoD::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_e(s) }, Branching0fromHtoE::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_f(s) }, Branching0fromHtoF::Backward(s) => { 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::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_g(s) }, Branching0fromHtoG::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; 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 if i % 2 == 0 => { let s: EndpointForwardH = choose_mpst_h_to_all!( s, Branching0fromHtoA::Forward, Branching0fromHtoB::Forward, Branching0fromHtoC::Forward, Branching0fromHtoD::Forward, Branching0fromHtoE::Forward, Branching0fromHtoF::Forward, Branching0fromHtoG::Forward ); let (_, s) = s.recv()?; recurs_h(s, i - 1) } i => { let s: EndpointBackwardH = choose_mpst_h_to_all!( s, Branching0fromHtoA::Backward, Branching0fromHtoB::Backward, Branching0fromHtoC::Backward, Branching0fromHtoD::Backward, Branching0fromHtoE::Backward, Branching0fromHtoF::Backward, Branching0fromHtoG::Backward ); let s = s.send(())?; 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 ring(c: &mut Criterion) { c.bench_function(&format!("ring 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 = ring, } criterion_main! { bench }