Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple benchmarking script #8

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
```
28 changes: 28 additions & 0 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -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.")