Skip to content

Commit

Permalink
benchmark hash functions
Browse files Browse the repository at this point in the history
  • Loading branch information
purificant committed Aug 5, 2021
1 parent 88a6fd1 commit 9638220
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_benchmark.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
""" This module contains benchmark tests intended to guide development of a performant codebase. """

import hashlib

import nacl.bindings
import pysodium
import pytest
Expand Down Expand Up @@ -77,3 +80,31 @@ def encrypt_and_decrypt():

plain_text = benchmark(encrypt_and_decrypt)
assert plain_text == MESSAGE


def test_hash_functions():
"""Test that hash functions produce the same digest."""
assert (
pysodium.crypto_generichash(MESSAGE, KEY)
== hashlib.blake2b(MESSAGE, key=KEY, digest_size=32).digest()
)


@pytest.mark.benchmark(group="hash")
def test_hash_one(benchmark):
"""Benchmark hash function."""

def hash_one():
return pysodium.crypto_generichash(MESSAGE, KEY)

benchmark(hash_one)


@pytest.mark.benchmark(group="hash")
def test_hash_two(benchmark):
"""Benchmark hash function."""

def hash_two():
return hashlib.blake2b(MESSAGE, key=KEY, digest_size=32).digest()

benchmark(hash_two)

0 comments on commit 9638220

Please sign in to comment.