@@ -41,24 +41,24 @@ fn participants_num() -> usize {
4141 * crate :: MAX_MALICIOUS + 1
4242}
4343
44- // // / Benches the triples protocol
45- // fn bench_triples(c: &mut Criterion) {
46- // let num = participants_num();
47- // let max_malicious = *MAX_MALICIOUS;
48- // let mut group = c.benchmark_group("triples");
49- // group.measurement_time(std::time::Duration::from_secs(200));
44+ /// Benches the triples protocol
45+ fn bench_triples ( c : & mut Criterion ) {
46+ let num = participants_num ( ) ;
47+ let max_malicious = * MAX_MALICIOUS ;
48+ let mut group = c. benchmark_group ( "triples" ) ;
49+ group. measurement_time ( std:: time:: Duration :: from_secs ( 200 ) ) ;
5050
51- // group.bench_function(
52- // format!("ot_ecdsa_triples_naive_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}"),
53- // |b| {
54- // b.iter_batched(
55- // || prepare_simulated_triples(participants_num()),
56- // |(rparticipant, rprot, sprot)| run_simulated_protocol(rparticipant, rprot, sprot),
57- // criterion::BatchSize::SmallInput,
58- // );
59- // },
60- // );
61- // }
51+ group. bench_function (
52+ format ! ( "ot_ecdsa_triples_naive_MAX_MALICIOUS_{max_malicious}_PARTICIPANTS_{num}" ) ,
53+ |b| {
54+ b. iter_batched (
55+ || prepare_simulated_triples ( participants_num ( ) ) ,
56+ |( rparticipant, rprot, sprot) | run_simulated_protocol ( rparticipant, rprot, sprot) ,
57+ criterion:: BatchSize :: SmallInput ,
58+ ) ;
59+ } ,
60+ ) ;
61+ }
6262
6363/// Benches the presigning protocol
6464fn bench_presign ( c : & mut Criterion ) {
@@ -126,39 +126,39 @@ fn prepare_triples(participant_num: usize) -> PreparedTriples {
126126 protocols
127127}
128128
129- // type PreparedSimulatedTriples = (
130- // Participant,
131- // Box<dyn Protocol<Output = Vec<(TripleShare, TriplePub)>>>,
132- // Simulator,
133- // );
134- // fn prepare_simulated_triples(participant_num: usize) -> PreparedSimulatedTriples {
135- // let mut protocols: Vec<(_, Box<dyn Protocol<Output = _>>)> =
136- // Vec::with_capacity(participant_num);
137- // let participants = generate_participants_with_random_ids(participant_num, &mut OsRng);
138-
139- // let rngs = create_multiple_rngs(&participants);
140-
141- // for (i, p) in participants.iter().enumerate() {
142- // let protocol = generate_triple_many::<2>(&participants, p, threshold(), rngs[i].clone())
143- // .expect("Triple generation should succeed");
144- // protocols.push((p, Box::new(protocol)));
145- // }
146- // let (_, protocolsnapshot) = run_protocol_with_snapshots(protocols)
147- // .expect("Running protocol with snapshot should not have issues");
148-
149- // // now preparing the simulator
150- // // choose the real_participant at random
151- // let index_real_participant = OsRng.gen_range(0..participant_num);
152- // let real_participant = participants[index_real_participant];
153- // let simulated_protocol = Simulator::new(real_participant, protocolsnapshot)
154- // .expect("Simulator should not be empty");
155- // let real_protocol =
156- // generate_triple_many::<2>(&participants, real_participant, threshold(), rngs[index_real_participant].clone())
157- // .map(|prot| Box::new(prot) as Box<dyn Protocol<Output = Vec<(TripleShare, TriplePub)>>>)
158- // .expect("The rerun of the triple generation should not but raising error");
159-
160- // (real_participant, real_protocol, simulated_protocol)
161- // }
129+ type PreparedSimulatedTriples = (
130+ Participant ,
131+ Box < dyn Protocol < Output = Vec < ( TripleShare , TriplePub ) > > > ,
132+ Simulator ,
133+ ) ;
134+ fn prepare_simulated_triples ( participant_num : usize ) -> PreparedSimulatedTriples {
135+ let mut protocols: Vec < ( _ , Box < dyn Protocol < Output = _ > > ) > =
136+ Vec :: with_capacity ( participant_num) ;
137+ let participants = generate_participants_with_random_ids ( participant_num, & mut OsRng ) ;
138+
139+ let rngs = create_multiple_rngs ( & participants) ;
140+
141+ for ( i, p) in participants. iter ( ) . enumerate ( ) {
142+ let protocol = generate_triple_many :: < 2 > ( & participants, * p, threshold ( ) , rngs[ i] . clone ( ) )
143+ . expect ( "Triple generation should succeed" ) ;
144+ protocols. push ( ( * p, Box :: new ( protocol) ) ) ;
145+ }
146+ let ( _, protocolsnapshot) = run_protocol_with_snapshots ( protocols)
147+ . expect ( "Running protocol with snapshot should not have issues" ) ;
148+
149+ // now preparing the simulator
150+ // choose the real_participant at random
151+ let index_real_participant = OsRng . gen_range ( 0 ..participant_num) ;
152+ let real_participant = participants[ index_real_participant] ;
153+ let simulated_protocol = Simulator :: new ( real_participant, protocolsnapshot)
154+ . expect ( "Simulator should not be empty" ) ;
155+ let real_protocol =
156+ generate_triple_many :: < 2 > ( & participants, real_participant, threshold ( ) , rngs[ index_real_participant] . clone ( ) )
157+ . map ( |prot| Box :: new ( prot) as Box < dyn Protocol < Output = Vec < ( TripleShare , TriplePub ) > > > )
158+ . expect ( "The rerun of the triple generation should not but raising error" ) ;
159+
160+ ( real_participant, real_protocol, simulated_protocol)
161+ }
162162
163163// type PreparedPresig = (
164164// Vec<(Participant, Box<dyn Protocol<Output = PresignOutput>>)>,
@@ -303,7 +303,7 @@ fn split_even_odd<T: Clone>(v: Vec<T>) -> (Vec<T>, Vec<T>) {
303303 ( even, odd)
304304}
305305
306- criterion_group ! ( benches, bench_presign) ;
307- // criterion_group!(benches, bench_triples, bench_presign);
306+ // criterion_group!(benches, bench_presign);
307+ criterion_group ! ( benches, bench_triples, bench_presign) ;
308308// criterion_group!(benches, bench_triples, bench_presign, bench_sign);
309309criterion:: criterion_main!( benches) ;
0 commit comments