Skip to content

Commit

Permalink
Add timing logging output.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLCaron committed Aug 8, 2024
1 parent 7b622e1 commit 6188071
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/org/cryptobiotic/eg/cli/RunBatchEncryption.kt
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ class RunBatchEncryption {
logger.info { " wrote ${invalidBallots.size} invalid ballots to $useInvalidDir" }
}

logger.debug { "Encryption with nthreads = $nthreads ${stopwatch.tookPer(count, "ballot")}" }
logger.info { "Encryption with nthreads = $nthreads ${stopwatch.tookPer(count, "ballot")}" }
val encryptionPerBallot = if (count == 0) 0 else (countEncryptions / count)
logger.debug {
logger.info {
" $countEncryptions total encryptions = $encryptionPerBallot per ballot ${
stopwatch.tookPer(
countEncryptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.cryptobiotic.eg.input.ManifestInputValidation
import org.cryptobiotic.eg.input.RandomBallotProvider
import org.cryptobiotic.eg.publish.makeConsumer
import org.cryptobiotic.eg.publish.makePublisher
import org.cryptobiotic.util.Stopwatch
import kotlin.random.Random
import kotlin.system.exitProcess

Expand Down Expand Up @@ -89,6 +90,7 @@ class RunExampleEncryption {
val chaining = electionInit.config.chainConfirmationCodes
val publisher = makePublisher(plaintextBallotDir)
var allOk = true
val stopwatch = Stopwatch() // start timing here

val ballotProvider = RandomBallotProvider(manifest)
repeat(nballots) {
Expand Down Expand Up @@ -126,6 +128,8 @@ class RunExampleEncryption {
} else {
if (!noexit) exitProcess(3)
}
logger.info { "RunExampleEncryption ${stopwatch.tookPer(nballots, "ballot")}" }

} catch (t: Throwable) {
logger.error { "Exception= ${t.message} ${t.stackTraceToString()}" }
if (!noexit) exitProcess(-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RunTrustedBallotDecryption {

companion object {
private val logger = KotlinLogging.logger("RunTrustedBallotDecryption")
private const val debug = true
private const val debug = false

@JvmStatic
fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.cryptobiotic.eg.decrypt.TallyDecryptor
import org.cryptobiotic.eg.election.*
import org.cryptobiotic.eg.publish.*
import org.cryptobiotic.util.ErrorMessages
import org.cryptobiotic.util.Stopwatch
import org.cryptobiotic.util.mergeErrorMessages
import kotlin.system.exitProcess

Expand Down Expand Up @@ -168,13 +169,17 @@ class RunTrustedTallyDecryption {
}
result.unwrap()
}
val stopwatch = Stopwatch() // start timing here

val errs = ErrorMessages("RunTrustedTallyDecryption")
val decryptedTally = decryptor.decrypt(encryptedTally, errs)
if (decryptedTally == null) {
logger.error { " encryptedTally.decrypt $inputDir has error=${errs}" }
return 5
}
val countEncryptions = countEncryptions(decryptedTally)
println( "runDecryptTally ${stopwatch.tookPer(countEncryptions, "encryptions")}")

val publisher = makePublisher(outputDir, false)
if (tallyResult != null) {
publisher.writeDecryptionResult(
Expand All @@ -198,3 +203,10 @@ class RunTrustedTallyDecryption {
}
}
}


fun countEncryptions(tally: DecryptedTallyOrBallot): Int {
return tally.contests.map { contest ->
1 + contest.selections.size
}.sum()
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ class RunDecryptBallotsTest {
assertEquals(42, n)
}

@Test
fun testDecryptBallotsAllSingleThreaded() {
val inputDir = "src/test/data/workflow/allAvailableEc"
val trusteeDir = "$inputDir/private_data/trustees"
val outputDir = "${Testing.testOut}/decrypt/testDecryptBallotsAll"
println("\ntestDecryptBallotsAll")
val (retval, n) = runDecryptBallots(
inputDir,
outputDir,
readDecryptingTrustees(inputDir, trusteeDir),
"ALL",
1,
)
assertEquals(0, retval)
assertEquals(42, n)
}

@Test
fun testDecryptBallotsSomeFromList() {
val inputDir = "src/test/data/workflow/someAvailableEc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import org.cryptobiotic.eg.decrypt.TallyDecryptor
import org.cryptobiotic.eg.election.DecryptedTallyOrBallot
import org.cryptobiotic.eg.election.ElectionInitialized
import org.cryptobiotic.eg.election.EncryptedBallot.BallotState
import org.cryptobiotic.eg.input.ManifestInputValidation
import org.cryptobiotic.eg.publish.makeConsumer
import org.cryptobiotic.util.ErrorMessages
import org.cryptobiotic.util.Stopwatch
import org.cryptobiotic.util.Testing
import kotlin.test.*

Expand Down Expand Up @@ -65,16 +67,22 @@ class RunTallyAccumulationTest {
val initResult = consumerIn.readElectionInitialized()
val electionInit = initResult.unwrap()
val manifest = consumerIn.makeManifest(electionInit.config.manifestBytes)
val styleCount = ManifestInputValidation(manifest).countEncryptions()

val accum = AccumulateTally(group, manifest, "name", electionInit.extendedBaseHash, electionInit.jointPublicKey)
val stopwatch = Stopwatch() // start timing here
var countEncryptions = 0

val errs = ErrorMessages("addCastBallots")
consumerIn.iterateAllCastBallots().forEach { eballot ->
accum.addCastBallot(eballot, errs)
countEncryptions += styleCount[eballot.ballotStyleId] ?: 0
}
assertFalse(errs.hasErrors())

val etally: EncryptedTally = accum.build()
println( "testAccumulateTally ${stopwatch.tookPer(countEncryptions, "encryptions")}")

val tally = decryptTally(group, etally, electionInit, readDecryptingTrustees(inputDir, trusteeDir))

val decryptResult = consumerIn.readDecryptionResult()
Expand Down
6 changes: 6 additions & 0 deletions src/test/kotlin/org/cryptobiotic/eg/verifier/VerifierTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class VerifierTest {
assertEquals(0, RunVerifier.runVerifier("src/test/data/workflow/someAvailableEc", 11, true))
}

@Test
fun verificationEcSingle() {
assertEquals(0, RunVerifier.runVerifier("src/test/data/workflow/allAvailableEc", 1, true))
assertEquals(0, RunVerifier.runVerifier("src/test/data/workflow/someAvailableEc", 1, true))
}

@Test
fun verificationInteger() {
assertEquals(0, RunVerifier.runVerifier("src/test/data/workflow/allAvailable", 11, true))
Expand Down

0 comments on commit 6188071

Please sign in to comment.