Skip to content

Commit f716332

Browse files
Add benchmark project (#198)
1 parent 41c05bf commit f716332

5 files changed

Lines changed: 111 additions & 2 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace ElectionGuard.Bench
9+
{
10+
11+
public static class BenchEncrypt
12+
{
13+
static readonly string plaintext_json = "{\"object_id\":\"some-external-id-string-123\",\"style_id\":\"some-ballot-style-id\",\"contests\":[{\"object_id\":\"some-referendum-contest-object-id\",\"ballot_selections\":[{\"object_id\":\"some-candidate-id-1\",\"vote\":1}]}]}";
14+
static readonly string manifest_json = "{\"ballot_styles\":[{\"geopolitical_unit_ids\":[\"some-geopoltical-unit-id\"],\"object_id\":\"some-ballot-style-id\"}],\"candidates\":[{\"object_id\":\"some-candidate-id-1\"},{\"object_id\":\"some-candidate-id-2\"},{\"object_id\":\"some-candidate-id-3\"}],\"contests\":[{\"ballot_selections\":[{\"candidate_id\":\"some-candidate-id-1\",\"object_id\":\"some-object-id-affirmative\",\"sequence_order\":0},{\"candidate_id\":\"some-candidate-id-2\",\"object_id\":\"some-object-id-negative\",\"sequence_order\":1}],\"electoral_district_id\":\"some-geopoltical-unit-id\",\"name\":\"some-referendum-contest-name\",\"number_elected\":1,\"object_id\":\"some-referendum-contest-object-id\",\"sequence_order\":0,\"vote_variation\":\"one_of_m\"},{\"ballot_selections\":[{\"candidate_id\":\"some-candidate-id-1\",\"object_id\":\"some-object-id-candidate-1\",\"sequence_order\":0},{\"candidate_id\":\"some-candidate-id-2\",\"object_id\":\"some-object-id-candidate-2\",\"sequence_order\":1},{\"candidate_id\":\"some-candidate-id-3\",\"object_id\":\"some-object-id-candidate-3\",\"sequence_order\":2}],\"electoral_district_id\":\"some-geopoltical-unit-id\",\"name\":\"some-candidate-contest-name\",\"number_elected\":2,\"object_id\":\"some-candidate-contest-object-id\",\"sequence_order\":1,\"vote_variation\":\"one_of_m\"}],\"election_scope_id\":\"some-scope-id\",\"end_date\":\"2021-02-04T13:30:10Z\",\"geopolitical_units\":[{\"name\":\"some-gp-unit-name\",\"object_id\":\"some-geopoltical-unit-id\",\"type\":\"unknown\"}],\"parties\":[{\"object_id\":\"some-party-id-1\"},{\"object_id\":\"some-party-id-2\"}],\"start_date\":\"2021-02-04T13:30:10Z\",\"type\":\"unknown\"}";
15+
16+
public static bool Bench_Encrypt_Ballot_Simple()
17+
{
18+
Stopwatch sw = new Stopwatch();
19+
sw.Start();
20+
// Configure the election context
21+
var keypair = ElGamalKeyPair.FromSecret(Constants.TWO_MOD_Q);
22+
var description = new Manifest(manifest_json);
23+
var manifest = new InternalManifest(description);
24+
var context = new CiphertextElectionContext(
25+
1UL, 1UL, keypair.PublicKey, Constants.TWO_MOD_Q, manifest.ManifestHash);
26+
var device = new EncryptionDevice(12345UL, 23456UL, 34567UL, "Location");
27+
var mediator = new EncryptionMediator(manifest, context, device);
28+
29+
var ballot = new PlaintextBallot(plaintext_json);
30+
31+
// Act
32+
var ciphertext = mediator.Encrypt(ballot, verifyProofs: false);
33+
34+
// TODO:
35+
36+
// json serialization
37+
//var json = ciphertext.ToJson();
38+
//var fromJson = new CiphertextBallot(json);
39+
40+
// binary serialization
41+
//var bson = ciphertext.Bson;
42+
//var fromBson = CiphertextBallot.FromBson(bson);
43+
44+
sw.Stop();
45+
Console.WriteLine("Elapsed={0}", sw.Elapsed);
46+
return true;
47+
}
48+
}
49+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>net5.0;net48</TargetFrameworks>
6+
<IsPackable>false</IsPackable>
7+
<Platforms>x64;x86</Platforms>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\ElectionGuard.Encryption\ElectionGuard.Encryption.csproj" />
12+
</ItemGroup>
13+
14+
<PropertyGroup Label="Library Paths">
15+
<ElectionGuardLibs>..\..\..\..\build\libs</ElectionGuardLibs>
16+
</PropertyGroup>
17+
<ItemGroup Label="C++ Built Libraries">
18+
<None Name="Windows x86" Visible="false" Include="$(ElectionGuardLibs)\msvc\Win32\src\$(Configuration)\*.dll*">
19+
<CopyToOutputDirectory Condition="'$(Platform)' == 'x86' AND '$(OS)' == 'Windows_NT'">Always</CopyToOutputDirectory>
20+
</None>
21+
<None Name="Windows x64" Visible="false" Include="$(ElectionGuardLibs)\msvc\x64\src\$(Configuration)\*.dll*">
22+
<CopyToOutputDirectory Condition="'$(Platform)' == 'x64' AND '$(OS)' == 'Windows_NT'">Always</CopyToOutputDirectory>
23+
</None>
24+
<None Name="Non Windows x64" Visible="false" Include="$(ElectionGuardLibs)\x86_64\$(Configuration)\src\*.dll*">
25+
<CopyToOutputDirectory Condition="'$(OS)' != 'Windows_NT'">Always</CopyToOutputDirectory>
26+
</None>
27+
<None Name="MacOS" Visible="false" Include="$(ElectionGuardLibs)\x86_64\$(Configuration)\src\*.dylib" CopyToOutputDirectory="Always" />
28+
<None Name="Linux" Visible="false" Include="$(ElectionGuardLibs)\x86_64\$(Configuration)\src\*.so" CopyToOutputDirectory="Always" />
29+
</ItemGroup>
30+
<ItemGroup Label="Json Test Data">
31+
<Content Include="..\..\..\..\data\ballot_in_simple.json"
32+
Link="Data\ballot_in_simple.json"
33+
CopyToOutputDirectory="Always" />
34+
<Content Include="..\..\..\..\data\election_manifest_jefferson_county.json"
35+
Link="Data\election_manifest_jefferson_county.json"
36+
CopyToOutputDirectory="Always" />
37+
<Folder Include="Data\" />
38+
</ItemGroup>
39+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using ElectionGuard.Bench;
2+
using System;
3+
4+
namespace ElectionGuard.Encryption.Bench
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
BenchEncrypt.Bench_Encrypt_Ballot_Simple();
11+
}
12+
}
13+
}

bindings/netstandard/ElectionGuard/ElectionGuard.Encryption.Tests/ElectionGuard.Encryption.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net5.0;net48</TargetFrameworks>
5-
65
<IsPackable>false</IsPackable>
7-
86
<Platforms>x64;x86</Platforms>
97
</PropertyGroup>
108

bindings/netstandard/ElectionGuard/ElectionGuard.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
README.md = README.md
1313
EndProjectSection
1414
EndProject
15+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectionGuard.Encryption.Bench", "ElectionGuard.Encryption.Bench\ElectionGuard.Encryption.Bench.csproj", "{06B6E480-D964-4351-8FF3-E62F652B8D4C}"
16+
EndProject
1517
Global
1618
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1719
Debug|x64 = Debug|x64
@@ -36,6 +38,14 @@ Global
3638
{111BE643-7978-4CDB-9FDC-0A198139A488}.Release|x64.Build.0 = Release|x64
3739
{111BE643-7978-4CDB-9FDC-0A198139A488}.Release|x86.ActiveCfg = Release|x86
3840
{111BE643-7978-4CDB-9FDC-0A198139A488}.Release|x86.Build.0 = Release|x86
41+
{06B6E480-D964-4351-8FF3-E62F652B8D4C}.Debug|x64.ActiveCfg = Debug|x64
42+
{06B6E480-D964-4351-8FF3-E62F652B8D4C}.Debug|x64.Build.0 = Debug|x64
43+
{06B6E480-D964-4351-8FF3-E62F652B8D4C}.Debug|x86.ActiveCfg = Debug|x86
44+
{06B6E480-D964-4351-8FF3-E62F652B8D4C}.Debug|x86.Build.0 = Debug|x86
45+
{06B6E480-D964-4351-8FF3-E62F652B8D4C}.Release|x64.ActiveCfg = Release|x64
46+
{06B6E480-D964-4351-8FF3-E62F652B8D4C}.Release|x64.Build.0 = Release|x64
47+
{06B6E480-D964-4351-8FF3-E62F652B8D4C}.Release|x86.ActiveCfg = Release|x86
48+
{06B6E480-D964-4351-8FF3-E62F652B8D4C}.Release|x86.Build.0 = Release|x86
3949
EndGlobalSection
4050
GlobalSection(SolutionProperties) = preSolution
4151
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)