From 03f05fbd89c8c156e86beb82eb574a2543ec8f84 Mon Sep 17 00:00:00 2001 From: Joey Wilhelm Date: Fri, 11 Mar 2022 11:55:29 -0700 Subject: [PATCH] Add a simple benchmarking script --- README.md | 17 +++++++++++++++++ benchmark.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 benchmark.py diff --git a/README.md b/README.md index 920dcc6..354ab71 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Asherah envelope encryption and key rotation library This is a wrapper of the Asherah Go implementation using the Cobhan FFI library +## Usage + Example code: ```python @@ -28,3 +30,18 @@ print(encrypted) decrypted = crypt.decrypt("partition", encrypted) print(decrypted) ``` + +## Benchmarking + +Included is a `benchmark.py` script that will give you an idea of the execution +speeds you can see from this library. Our goal is to make this as performant as +possible, as demonstrated by this example output: + +```sh +> python benchmark.py +Benchmarking encrypt/decrypt round trips of "mysecretdata". +Executed 100 iterations in 0.026045440000000003 seconds. +Executed 1000 iterations in 0.237702095 seconds. +Executed 10000 iterations in 2.3570790550000003 seconds. +Executed 100000 iterations in 23.717442475 seconds. +``` diff --git a/benchmark.py b/benchmark.py new file mode 100644 index 0000000..0595eb5 --- /dev/null +++ b/benchmark.py @@ -0,0 +1,28 @@ +import gc +import timeit + +from asherah import Asherah, AsherahConfig + +config = AsherahConfig( + kms_type="static", + metastore="memory", + service_name="TestService", + product_id="TestProduct", + session_cache=True, +) +crypt = Asherah() +crypt.setup(config) + +data = b"mysecretdata" + +crypt_cycle = """ +encrypted = crypt.encrypt("partition", data) +decrypted = crypt.decrypt("partition", encrypted) +""" + +print(f'Benchmarking encrypt/decrypt round trips of "{data}".') +for loop_size in [100, 1000, 10000, 100000]: + result = timeit.timeit( + stmt=crypt_cycle, setup="gc.enable()", number=loop_size, globals=globals() + ) + print(f"Executed {loop_size} iterations in {result} seconds.")