1 {-# LANGUAGE OverloadedStrings #-}
4 import qualified Data.List as List
5 import qualified Data.Text as Text
10 makeElection :: SubGroup q => Int -> Int -> Election q
11 makeElection nQuests nChoices = Election
12 { election_name = Text.pack $ "elec"<>show nQuests<>show nChoices
13 , election_description = "benchmarkable election"
15 , election_publicKey =
16 let secKey = credentialSecretKey election_uuid (Credential "xLcs7ev6Jy6FHHE") in
18 , election_hash = Hash "" -- FIXME: when implemented
19 , election_questions =
20 (<$> [1..nQuests]) $ \quest -> Question
21 { question_text = Text.pack $ "quest"<>show quest
22 , question_choices = (<$> [1..nChoices]) $ \choice -> Text.pack $ "choice"<>show choice
23 , question_mini = zero
24 , question_maxi = sum $ List.replicate nChoices one
26 } where election_uuid = UUID "xLcs7ev6Jy6FHH"
28 makeVotes :: Election q -> [[Bool]]
29 makeVotes Election{..} =
30 [ [ True | _choice <- question_choices quest ]
31 | quest <- election_questions
34 makeBallot :: forall q. SubGroup q => Election q -> Ballot q
36 case runExcept $ (`evalStateT` mkStdGen seed) $ do
37 ballotSecKey :: SecretKey q <- randomSecretKey
38 encryptBallot elec (Just ballotSecKey) $
40 Right ballot -> ballot
41 Left err -> error ("encryptBallot: "<>show err)
45 benchEncryptBallot :: forall q. Params q => Int -> Int -> Benchmark
46 benchEncryptBallot nQuests nChoices =
47 env setupEnv $ \ ~elec ->
48 bench ("(nQuests="<>show nQuests<>")*(nChoices="<>show nChoices<>")=="<>show (nQuests * nChoices)) $
52 let elec :: Election q = makeElection nQuests nChoices
55 benchVerifyBallot :: forall q. Params q => Int -> Int -> Benchmark
56 benchVerifyBallot nQuests nChoices =
57 env setupEnv $ \ ~(elec,ballot) ->
58 bench ("(nQuests="<>show nQuests<>")*(nChoices="<>show nChoices<>")=="<>show (nQuests * nChoices)) $
59 nf (verifyBallot elec) ballot
62 let elec :: Election q = makeElection nQuests nChoices
63 let ballot = makeBallot elec
66 benchmarks :: [Benchmark]
68 -- let inputs = [(1,2), (5,5), (10,5), (5,10){-, (10,6), (10,7), (15,5)-}] in
71 | nQ <- [1,5,10,15{-,20,25-}]
75 [ bgroup "encryptBallot"
76 [ benchEncryptBallot @WeakParams nQuests nChoices
77 | (nQuests,nChoices) <- inputs
79 , bgroup "verifyBallot"
80 [ benchVerifyBallot @BeleniosParams nQuests nChoices
81 | (nQuests,nChoices) <- inputs
84 , bgroup "BeleniosParams"
85 [ bgroup "encryptBallot"
86 [ benchEncryptBallot @BeleniosParams nQuests nChoices
87 | (nQuests,nChoices) <- inputs
89 , bgroup "verifyBallot"
90 [ benchVerifyBallot @BeleniosParams nQuests nChoices
91 | (nQuests,nChoices) <- inputs