33using System . Diagnostics ;
44using System . Linq ;
55using System . Text ;
6+ using System . Threading ;
67using System . Threading . Tasks ;
78using ElectionGuard . Encryption . Utils ;
89
@@ -11,6 +12,7 @@ namespace ElectionGuard.Encryption.Bench
1112
1213 public class BenchEncrypt : Fixture
1314 {
15+ readonly int MAX_COMPLETE_DELAY = 7000 ;
1416 ElementModQ nonce ;
1517 ElGamalKeyPair keypair ;
1618 Manifest manifest ;
@@ -41,6 +43,9 @@ public override void Run()
4143 Bench_Encrypt_BallotFull_NoProofCheck ( ) ;
4244 Bench_Encrypt_BallotFull_WithProofCheck ( ) ;
4345 Bench_Encrypt_Ballot_Compact_NoProofCheck ( ) ;
46+
47+ Setup_Precompute_Buffers ( ) ;
48+ Bench_Encrypt_BallotFull_NoProofCheck ( ) ;
4449 // TODO: Bench_Encrypt_Ballot_Compact_WithProofCheck();
4550 }
4651
@@ -79,5 +84,24 @@ public void Bench_Encrypt_Ballot_Compact_WithProofCheck()
7984 var ciphertext = Encrypt . CompactBallot ( ballot , internalManifest , context , device . GetHash ( ) , nonce , true ) ;
8085 } ) ;
8186 }
87+
88+ public void Setup_Precompute_Buffers ( )
89+ {
90+ Console . WriteLine ( "Setup_Precompute_Buffers" ) ;
91+ var waitHandle = new AutoResetEvent ( false ) ;
92+
93+ Precompute precompute = new Precompute ( ) ;
94+ precompute . CompletedEvent += ( PrecomputeStatus completedStatus ) =>
95+ {
96+ waitHandle . Set ( ) ;
97+ } ;
98+ precompute . StartPrecomputeAsync ( keypair . PublicKey , 1000 ) ;
99+ var waitReturn = waitHandle . WaitOne ( MAX_COMPLETE_DELAY ) ;
100+ Run ( ( ) =>
101+ {
102+ precompute . StopPrecompute ( ) ;
103+ } ) ;
104+ }
105+
82106 }
83107}
0 commit comments