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

Performance vs hashlib (SHA-512) #277

Closed
bschollnick opened this issue Apr 4, 2019 · 1 comment
Closed

Performance vs hashlib (SHA-512) #277

bschollnick opened this issue Apr 4, 2019 · 1 comment

Comments

@bschollnick
Copy link

I was hoping to see a speed increase from hashlib, but pycryptodome appears to be running ~6x slower that hashlib with SHA-512 generation...

python 3.7.1 (64bit) on windows 10 64-bit.

`from random import randint
import string
import timeit
import hashlib

builtin = """
import hashlib
import random
import string
max = 1024
randomString = "This is a test only a test, of the python string, going through this shite, to see if there is any performance difference between hashlib and a different library"
sha = hashlib.sha512()
sha.update(randomString.encode("utf-16"))
sha.hexdigest()
"""

pcrypto = """
from Crypto.Hash import SHA512
import random
import string
max = 1024
randomString = "This is a test only a test, of the python string, going through this shite, to see if there is any performance difference between hashlib and a different library"
sha = SHA512.new()
sha.update(randomString.encode("utf-16"))
sha.hexdigest()
"""
print ("hashlib - ",timeit.timeit(stmt=builtin, number=10000))
print ("PCrytpo - ",timeit.timeit(stmt=pcrypto, number=10000))
`
hashlib - 0.036552100000000004
PCrytpo - 0.4269634

Is this expected? I'm happy to work with you to diagnose this further...
I have code that is heavily utilizing SHA-512 hashes and if there is a faster way to generate them, I'm more than happy to put some effort in to assist.

@Legrandin
Copy link
Owner

hashlib is backed by openssl, which implements SHA512 in assembly using AVX instructions (assuming you run a modern X86 CPU), so yes it is expected to be faster than PyCryptodome, which only uses portable C (with some SSE2 intrinsics here and there).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants