Skip to content

Commit 9638220

Browse files
committed
benchmark hash functions
1 parent 88a6fd1 commit 9638220

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_benchmark.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
""" This module contains benchmark tests intended to guide development of a performant codebase. """
2+
3+
import hashlib
4+
25
import nacl.bindings
36
import pysodium
47
import pytest
@@ -77,3 +80,31 @@ def encrypt_and_decrypt():
7780

7881
plain_text = benchmark(encrypt_and_decrypt)
7982
assert plain_text == MESSAGE
83+
84+
85+
def test_hash_functions():
86+
"""Test that hash functions produce the same digest."""
87+
assert (
88+
pysodium.crypto_generichash(MESSAGE, KEY)
89+
== hashlib.blake2b(MESSAGE, key=KEY, digest_size=32).digest()
90+
)
91+
92+
93+
@pytest.mark.benchmark(group="hash")
94+
def test_hash_one(benchmark):
95+
"""Benchmark hash function."""
96+
97+
def hash_one():
98+
return pysodium.crypto_generichash(MESSAGE, KEY)
99+
100+
benchmark(hash_one)
101+
102+
103+
@pytest.mark.benchmark(group="hash")
104+
def test_hash_two(benchmark):
105+
"""Benchmark hash function."""
106+
107+
def hash_two():
108+
return hashlib.blake2b(MESSAGE, key=KEY, digest_size=32).digest()
109+
110+
benchmark(hash_two)

0 commit comments

Comments
 (0)