Optimized.

hashlib is replaced with _sha512.
"0"*difficulty is only calculated once now.
start_string converted to ASCII.
No longer using 'test' variable to hold hash.
hash.startswith(null) replaced with hash[0:difficulty] == null.
When possible, digest() is used instead of hexdigest().