You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/python3
from hashlib import sha512
from Cryptodome.Hash import SHA512
import time
initial_digest=b'test.test.test.test.test'
iterations=500000
# *******************
digest=initial_digest
start = time.time()
for counter in range(iterations):
digest=sha512(digest).digest()
end = time.time()
print(" Time (hashlib sha512):\t", end - start)
# *******************
digest=initial_digest
start = time.time()
for counter in range(iterations):
digest=SHA512.new(data=digest).digest()
end = time.time()
print("Time (cryptodome sha512):\t", end - start)
# *******************
digest=initial_digest
start = time.time()
MySHA512=SHA512.new
for counter in range(iterations):
digest=MySHA512(data=digest).digest()
end = time.time()
print("Time (cryptodome sha512):\t", end - start)
Output on my computer:
valentin@computer:~/python/test3$ ./test-sha512.py
Time (hashlib sha512): 0.5348014831542969
Time (cryptodome sha512): 7.416509389877319
Time (cryptodome sha512): 7.28940749168396
valentin@computer:~/python/test3$ ./test-sha512.py
Time (hashlib sha512): 0.5275444984436035
Time (cryptodome sha512): 7.590082168579102
Time (cryptodome sha512): 7.583686351776123
valentin@computer:~/python/test3$ ./test-sha512.py
Time (hashlib sha512): 0.5171098709106445
Time (cryptodome sha512): 7.440552234649658
Time (cryptodome sha512): 7.221668243408203
valentin@computer:~/python/test3$
Is this because of Cryptodome using more object oriented approach? Or the underlying implementation of the algorithm is somehow inefficient?
The text was updated successfully, but these errors were encountered:
Example code:
Output on my computer:
Is this because of Cryptodome using more object oriented approach? Or the underlying implementation of the algorithm is somehow inefficient?
The text was updated successfully, but these errors were encountered: