#![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, session::Session}; 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, I); // Types // A enum Branching0fromItoA { Forward( MeshedChannels< Send<(), End>, End, End, End, End, End, End, RecursAtoI, RoleB>, NameA, >, ), Backward( MeshedChannels< Recv<(), End>, End, End, End, End, End, End, RecursAtoI, RoleB>, NameA, >, ), Done(MeshedChannels), } type RecursAtoI = ::Dual; // B enum Branching0fromItoB { Forward( MeshedChannels< Recv<(), End>, Send<(), End>, End, End, End, End, End, RecursBtoI, RoleA>>, NameB, >, ), Backward( MeshedChannels< Send<(), End>, Recv<(), End>, End, End, End, End, End, RecursBtoI, RoleC>>, NameB, >, ), Done(MeshedChannels), } type RecursBtoI = ::Dual; // C enum Branching0fromItoC { Forward( MeshedChannels< End, Recv<(), End>, Send<(), End>, End, End, End, End, RecursCtoI, RoleB>>, NameC, >, ), Backward( MeshedChannels< End, Send<(), End>, Recv<(), End>, End, End, End, End, RecursCtoI, RoleD>>, NameC, >, ), Done(MeshedChannels), } type RecursCtoI = ::Dual; // D enum Branching0fromItoD { Forward( MeshedChannels< End, End, Recv<(), End>, Send<(), End>, End, End, End, RecursDtoI, RoleC>>, NameD, >, ), Backward( MeshedChannels< End, End, Send<(), End>, Recv<(), End>, End, End, End, RecursDtoI, RoleE>>, NameD, >, ), Done(MeshedChannels), } type RecursDtoI = ::Dual; // E enum Branching0fromItoE { Forward( MeshedChannels< End, End, End, Recv<(), End>, Send<(), End>, End, End, RecursEtoI, RoleD>>, NameE, >, ), Backward( MeshedChannels< End, End, End, Send<(), End>, Recv<(), End>, End, End, RecursEtoI, RoleF>>, NameE, >, ), Done(MeshedChannels), } type RecursEtoI = ::Dual; // F enum Branching0fromItoF { Forward( MeshedChannels< End, End, End, End, Recv<(), End>, Send<(), End>, End, RecursFtoI, RoleE>>, NameF, >, ), Backward( MeshedChannels< End, End, End, End, Send<(), End>, Recv<(), End>, End, RecursFtoI, RoleG>>, NameF, >, ), Done(MeshedChannels), } type RecursFtoI = ::Dual; // G enum Branching0fromItoG { Forward( MeshedChannels< End, End, End, End, End, Recv<(), End>, Send<(), End>, RecursGtoI, RoleF>>, NameG, >, ), Backward( MeshedChannels< End, End, End, End, End, Send<(), End>, Recv<(), End>, RecursGtoI, RoleH>>, NameG, >, ), Done(MeshedChannels), } type RecursGtoI = ::Dual; // H enum Branching0fromItoH { Forward( MeshedChannels< End, End, End, End, End, End, Recv<(), End>, Send<(), RecursHtoI>, RoleG>>, NameH, >, ), Backward( MeshedChannels< End, End, End, End, End, End, Send<(), End>, Recv<(), RecursHtoI>, RoleI>>, NameH, >, ), Done(MeshedChannels), } type RecursHtoI = ::Dual; // I type Choose0fromItoA = Send; type Choose0fromItoB = Send; type Choose0fromItoC = Send; type Choose0fromItoD = Send; type Choose0fromItoE = Send; type Choose0fromItoF = Send; type Choose0fromItoG = Send; type Choose0fromItoH = Send; type EndpointForwardI = MeshedChannels< Choose0fromItoA, Choose0fromItoB, Choose0fromItoC, Choose0fromItoD, Choose0fromItoE, Choose0fromItoF, Choose0fromItoG, Recv<(), Choose0fromItoH>, RoleH, NameI, >; type EndpointBackwardI = MeshedChannels< Choose0fromItoA, Choose0fromItoB, Choose0fromItoC, Choose0fromItoD, Choose0fromItoE, Choose0fromItoF, Choose0fromItoG, Send<(), Choose0fromItoH>, RoleH, NameI, >; // 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, NameH>; type EndpointI = MeshedChannels< Choose0fromItoA, Choose0fromItoB, Choose0fromItoC, Choose0fromItoD, Choose0fromItoE, Choose0fromItoF, Choose0fromItoG, Choose0fromItoH, RoleBroadcast, NameI, >; fn endpoint_a(s: EndpointA) -> Result<(), Box> { offer_mpst!(s, { Branching0fromItoA::Done(s) => { s.close() }, Branching0fromItoA::Forward(s) => { let s = s.send(())?; endpoint_a(s) }, Branching0fromItoA::Backward(s) => { let (_, s) = s.recv()?; endpoint_a(s) }, }) } #[inline] fn endpoint_b(s: EndpointB) -> Result<(), Box> { offer_mpst!(s, { Branching0fromItoB::Done(s) => { s.close() }, Branching0fromItoB::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_b(s) }, Branching0fromItoB::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_b(s) }, }) } #[inline] fn endpoint_c(s: EndpointC) -> Result<(), Box> { offer_mpst!(s, { Branching0fromItoC::Done(s) => { s.close() }, Branching0fromItoC::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_c(s) }, Branching0fromItoC::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_c(s) }, }) } #[inline] fn endpoint_d(s: EndpointD) -> Result<(), Box> { offer_mpst!(s, { Branching0fromItoD::Done(s) => { s.close() }, Branching0fromItoD::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_d(s) }, Branching0fromItoD::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_d(s) }, }) } #[inline] fn endpoint_e(s: EndpointE) -> Result<(), Box> { offer_mpst!(s, { Branching0fromItoE::Done(s) => { s.close() }, Branching0fromItoE::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_e(s) }, Branching0fromItoE::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_e(s) }, }) } #[inline] fn endpoint_f(s: EndpointF) -> Result<(), Box> { offer_mpst!(s, { Branching0fromItoF::Done(s) => { s.close() }, Branching0fromItoF::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_f(s) }, Branching0fromItoF::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_f(s) }, }) } #[inline] fn endpoint_g(s: EndpointG) -> Result<(), Box> { offer_mpst!(s, { Branching0fromItoG::Done(s) => { s.close() }, Branching0fromItoG::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_g(s) }, Branching0fromItoG::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_g(s) }, }) } #[inline] fn endpoint_h(s: EndpointH) -> Result<(), Box> { offer_mpst!(s, { Branching0fromItoH::Done(s) => { s.close() }, Branching0fromItoH::Forward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_h(s) }, Branching0fromItoH::Backward(s) => { let ((), s) = s.recv()?; let s = s.send(())?; endpoint_h(s) }, }) } #[inline] fn endpoint_i(s: EndpointI) -> Result<(), Box> { let mut temp_s = s; for i in 1..LOOPS { temp_s = recurs_i(temp_s, i)?; } let s = choose_mpst_i_to_all!( temp_s, Branching0fromItoA::Done, Branching0fromItoB::Done, Branching0fromItoC::Done, Branching0fromItoD::Done, Branching0fromItoE::Done, Branching0fromItoF::Done, Branching0fromItoG::Done, Branching0fromItoH::Done ); s.close() } fn recurs_i(s: EndpointI, index: i64) -> Result> { match index { i if i % 2 == 0 => { let s: EndpointForwardI = choose_mpst_i_to_all!( s, Branching0fromItoA::Forward, Branching0fromItoB::Forward, Branching0fromItoC::Forward, Branching0fromItoD::Forward, Branching0fromItoE::Forward, Branching0fromItoF::Forward, Branching0fromItoG::Forward, Branching0fromItoH::Forward ); let (_, s) = s.recv()?; Ok(s) } _ => { let s: EndpointBackwardI = choose_mpst_i_to_all!( s, Branching0fromItoA::Backward, Branching0fromItoB::Backward, Branching0fromItoC::Backward, Branching0fromItoD::Backward, Branching0fromItoE::Backward, Branching0fromItoF::Backward, Branching0fromItoG::Backward, Branching0fromItoH::Backward ); let s = s.send(())?; Ok(s) } } } fn aux() { let (thread_a, thread_b, thread_c, thread_d, thread_e, thread_f, thread_g, thread_h, thread_i) = 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), black_box(endpoint_i), ); 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(); thread_i.join().unwrap(); } ///////////////////////// static LOOPS: i64 = 100; pub fn ring(c: &mut Criterion) { c.bench_function(&format!("ring nine baking inline {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 }