summaryrefslogtreecommitdiff
path: root/benchmarks/Election.hs
diff options
context:
space:
mode:
Diffstat (limited to 'benchmarks/Election.hs')
-rw-r--r--benchmarks/Election.hs66
1 files changed, 33 insertions, 33 deletions
diff --git a/benchmarks/Election.hs b/benchmarks/Election.hs
index 8af3fde..c51b40d 100644
--- a/benchmarks/Election.hs
+++ b/benchmarks/Election.hs
@@ -8,15 +8,15 @@ import qualified Text.Printf as Printf
import Voting.Protocol
import Utils
-makeElection :: SubGroup q => Int -> Int -> Election q
-makeElection nQuests nChoices = Election
+makeElection :: forall c. Reifies c FFC => Int -> Int -> Election c
+makeElection nQuests nChoices = hashElection $ Election
{ election_name = Text.pack $ "elec"<>show nQuests<>show nChoices
, election_description = "benchmarkable election"
, election_uuid
- , election_PublicKey =
+ , election_crypto = ElectionCrypto_FFC (reflect (Proxy::Proxy c)) $
let secKey = credentialSecretKey election_uuid (Credential "xLcs7ev6Jy6FHHE") in
publicKey secKey
- , election_hash = Hash "" -- FIXME: when implemented
+ , election_hash = Hash ""
, election_questions =
(<$> [1..nQuests]) $ \quest -> Question
{ question_text = Text.pack $ "quest"<>show quest
@@ -26,16 +26,16 @@ makeElection nQuests nChoices = Election
}
} where election_uuid = UUID "xLcs7ev6Jy6FHH"
-makeVotes :: Election q -> [[Bool]]
+makeVotes :: Election c -> [[Bool]]
makeVotes Election{..} =
[ True : List.tail [ False | _choice <- question_choices quest ]
| quest <- election_questions
]
-makeBallot :: forall q. SubGroup q => Election q -> Ballot q
+makeBallot :: Reifies c FFC => Election c -> Ballot c
makeBallot elec =
case runExcept $ (`evalStateT` mkStdGen seed) $ do
- ballotSecKey :: SecretKey q <- randomSecretKey
+ ballotSecKey <- randomSecretKey
encryptBallot elec (Just ballotSecKey) $
makeVotes elec of
Right ballot -> ballot
@@ -43,7 +43,7 @@ makeBallot elec =
where
seed = 0
-titleElection :: Election q -> String
+titleElection :: Election c -> String
titleElection Election{..} =
Printf.printf "(questions=%i)×(choices=%i)==%i"
nQuests nChoices (nQuests * nChoices)
@@ -51,26 +51,26 @@ titleElection Election{..} =
nQuests = List.length election_questions
nChoices = List.foldr max 0 $ List.length . question_choices <$> election_questions
-benchEncryptBallot :: forall q. Params q => Int -> Int -> Benchmark
-benchEncryptBallot nQuests nChoices =
- env setupEnv $ \ ~elec ->
- bench (titleElection elec) $
- nf makeBallot elec
- where
- setupEnv = do
- let elec :: Election q = makeElection nQuests nChoices
- return elec
+benchEncryptBallot :: FFC -> Int -> Int -> Benchmark
+benchEncryptBallot ffc nQuests nChoices =
+ reify ffc $ \(Proxy::Proxy c) ->
+ let setupEnv = do
+ let elec :: Election c = makeElection nQuests nChoices
+ return elec in
+ env setupEnv $ \ ~(elec) ->
+ bench (titleElection elec) $
+ nf makeBallot elec
-benchVerifyBallot :: forall q. Params q => Int -> Int -> Benchmark
-benchVerifyBallot nQuests nChoices =
- env setupEnv $ \ ~(elec,ballot) ->
- bench (titleElection elec) $
- nf (verifyBallot elec) ballot
- where
- setupEnv = do
- let elec :: Election q = makeElection nQuests nChoices
- let ballot = makeBallot elec
- return (elec,ballot)
+benchVerifyBallot :: FFC -> Int -> Int -> Benchmark
+benchVerifyBallot ffc nQuests nChoices =
+ reify ffc $ \(Proxy::Proxy c) ->
+ let setupEnv = do
+ let elec :: Election c = makeElection nQuests nChoices
+ let ballot = makeBallot elec
+ return (elec,ballot) in
+ env setupEnv $ \ ~(elec, ballot) ->
+ bench (titleElection elec) $
+ nf (verifyBallot elec) ballot
benchmarks :: [Benchmark]
benchmarks =
@@ -79,23 +79,23 @@ benchmarks =
| nQ <- [1,5,10,15,20,25]
, nC <- [5,7]
] in
- [ bgroup "WeakParams"
+ [ bgroup "weakFFC"
[ bgroup "encryptBallot"
- [ benchEncryptBallot @WeakParams nQuests nChoices
+ [ benchEncryptBallot weakFFC nQuests nChoices
| (nQuests,nChoices) <- inputs
]
, bgroup "verifyBallot"
- [ benchVerifyBallot @WeakParams nQuests nChoices
+ [ benchVerifyBallot weakFFC nQuests nChoices
| (nQuests,nChoices) <- inputs
]
]
- , bgroup "BeleniosParams"
+ , bgroup "beleniosFFC"
[ bgroup "encryptBallot"
- [ benchEncryptBallot @BeleniosParams nQuests nChoices
+ [ benchEncryptBallot beleniosFFC nQuests nChoices
| (nQuests,nChoices) <- inputs
]
, bgroup "verifyBallot"
- [ benchVerifyBallot @BeleniosParams nQuests nChoices
+ [ benchVerifyBallot beleniosFFC nQuests nChoices
| (nQuests,nChoices) <- inputs
]
]