Skip to content

Commit

Permalink
some speed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Jul 27, 2024
1 parent adbe970 commit f8d1937
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions speed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from xof_py import Shaker128
import time
import os
from Crypto.Hash.SHAKE128 import SHAKE128_XOF

for _ in range(100):
absorb = os.urandom(32)
Expand All @@ -11,6 +12,15 @@
b = Shaker128(absorb).finalize().read(n)
assert a == b

for _ in range(3):
absorb = os.urandom(32)
xof1 = Shaker128(absorb).finalize()
xof2 = Shaker128(absorb).finalize()
a = shake_128(absorb).digest(100_000)
b = b"".join(xof1.read(1) for _ in range(100_000))
c = xof2.read(100_000)
assert a == b == c

random.seed(0)
t0 = time.time()
xof = Shaker128(b"123").finalize()
Expand All @@ -27,3 +37,29 @@
print(f"10_000 calls with hashlib: {time.time() - t0 }")

print("-" * 80)

t0 = time.time()
xof = Shaker128(b"123").finalize()
for _ in range(1_000_000):
a = xof.read(1)
print(f"1_000_000 single byte reads pyo3: {time.time() - t0 }")

t0 = time.time()
xof = SHAKE128_XOF()
xof.update(b"123")
for _ in range(1_000_000):
a = xof.read(1)
print(f"1_000_000 single byte reads pycryptodome: {time.time() - t0 }")

t0 = time.time()
xof = Shaker128(b"123").finalize()
for _ in range(1_000_000):
a = xof.read(168)
print(f"100_000 block reads pyo3: {time.time() - t0 }")

t0 = time.time()
xof = SHAKE128_XOF()
xof.update(b"123")
for _ in range(1_000_000):
a = xof.read(168)
print(f"100_000 block reads pycryptodome: {time.time() - t0 }")

0 comments on commit f8d1937

Please sign in to comment.