Skip to main content
added 4 characters in body
Source Link
lenik
  • 23.6k
  • 4
  • 38
  • 44

I would definitely recommend to avoid converting uint64 to strings. You may use struct for the gettingto get the binary data that can be subsequently fed to the hashlib.md5():

>>> import struct, hashlib >>> a = struct.pack( '<Q', 0x423423423423 ) >>> a '#4B#4B\x00\x00' >>> hashlib.md5( a ).hexdigest() 'de0fc624a1b287881eee581ed83500d1' >>> 

This would definitely will speed up the process, since there's no conversion, just simple byte copies.

Also, gettig hexdigest() may be replaced with digest(), that returns the binary data, which is faster that converting that to hex string. Depending on how you're planning to use that data later, this might be a good approach.

I would definitely recommend to avoid converting uint64 to strings. You may use struct for the getting the binary data that can be fed to the hashlib.md5():

>>> import struct, hashlib >>> a = struct.pack( '<Q', 0x423423423423 ) >>> a '#4B#4B\x00\x00' >>> hashlib.md5( a ).hexdigest() 'de0fc624a1b287881eee581ed83500d1' >>> 

This would definitely will speed up the process, since there's no conversion, just simple byte copies.

I would definitely recommend to avoid converting uint64 to strings. You may use struct to get the binary data that can be subsequently fed to the hashlib.md5():

>>> import struct, hashlib >>> a = struct.pack( '<Q', 0x423423423423 ) >>> a '#4B#4B\x00\x00' >>> hashlib.md5( a ).hexdigest() 'de0fc624a1b287881eee581ed83500d1' >>> 

This would definitely will speed up the process, since there's no conversion, just simple byte copies.

Also, gettig hexdigest() may be replaced with digest(), that returns the binary data, which is faster that converting that to hex string. Depending on how you're planning to use that data later, this might be a good approach.

Source Link
lenik
  • 23.6k
  • 4
  • 38
  • 44

I would definitely recommend to avoid converting uint64 to strings. You may use struct for the getting the binary data that can be fed to the hashlib.md5():

>>> import struct, hashlib >>> a = struct.pack( '<Q', 0x423423423423 ) >>> a '#4B#4B\x00\x00' >>> hashlib.md5( a ).hexdigest() 'de0fc624a1b287881eee581ed83500d1' >>> 

This would definitely will speed up the process, since there's no conversion, just simple byte copies.