I am trying to compute md5 hash of a file with the function hashlib.md5() from hashlib module.
So that I writed this piece of code:
Buffer = 128
f = open("c:\\file.tct", "rb")
m = hashlib.md5()
while True:
p = f.read(Buffer)
if len(p) != 0:
m.update(p)
else:
break
print m.hexdigest()
f.close()
I noted the function update is faster if I increase Buffer variable value with 64, 128, 256 and so on. There is a upper limit I cannot exceed? I suppose it might only a RAM memory problem but I don't know.
The buffer value is the number of bytes that is read and stored in memory at once, so yes, the only limit is your available memory.
However, bigger values are not automatically faster. At some point, you might run into memory paging issues or other slowdowns with memory allocation if the buffer is too large. You should experiment with larger and larger values until you hit diminishing returns in speed.