Skip to content

Commit

Permalink
added ccakem performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
PyryL committed Nov 30, 2023
1 parent 72881e9 commit 15e54d1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions perf_tests/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from perf_tests.test_encryption import runner as encryption_test_runner
from perf_tests.test_ccakem import runner as ccakem_test_runner

encryption_test_runner()
ccakem_test_runner()
39 changes: 39 additions & 0 deletions perf_tests/test_ccakem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from time import time
from kyber.ccakem import ccakem_generate_keys, ccakem_encrypt, ccakem_decrypt

def run_test() -> tuple[float, float, float]:
t0 = time()

private_key, public_key = ccakem_generate_keys()

t1 = time()

ciphertext, shared_secret1 = ccakem_encrypt(public_key)

t2 = time()

shared_secret2 = ccakem_decrypt(ciphertext, private_key)

t3 = time()

assert shared_secret1 == shared_secret2

return (t1-t0, t2-t1, t3-t2)

def runner():
print("Starting ccakem performance test (about 2 mins)")

test_iters = 250
averages = [0, 0, 0]

for _ in range(test_iters):
durations = run_test()
averages = [averages[i]+durations[i] for i in range(3)]

print("Results (averages):")
print(f"Keypair generation: {averages[0]/test_iters:.5f} sec")
print(f"Encryption: {averages[1]/test_iters:.5f} sec")
print(f"Decryption: {averages[2]/test_iters:.5f} sec")

if __name__ == "__main__":
runner()

0 comments on commit 15e54d1

Please sign in to comment.