blake3 : 335251.50 per second
blake2s: 715722.22 per second
blake2b: 663446.58 per second
blake2 can run 2x faster than blake3 for short messages
The result can be outdated; you should test it on your own for your reference.
blake3 : 335251.50 per second
blake2s: 715722.22 per second
blake2b: 663446.58 per second
blake2 can run 2x faster than blake3 for short messages
The result can be outdated; you should test it on your own for your reference.
from blake3 import blake3 | |
from hashlib import blake2s, blake2b | |
from itertools import count | |
from more_itertools import take | |
unit_loop = 1000 | |
output_size = 10 | |
iterator = count(start=1000000000) | |
def test_hash_time(hash): | |
for x in take(unit_loop, iterator): | |
hash(f'hashing {x}!'.encode()) | |
def hash_a(data): | |
return blake3(data, multithreading=False).hexdigest(length=output_size) | |
def hash_b(data): | |
return blake2s(data, digest_size=output_size).hexdigest() | |
def hash_c(data): | |
return blake2b(data, digest_size=output_size).hexdigest() | |
# taken from: https://stackoverflow.com/a/11857869/1713808 | |
def timereps(reps, func): | |
from time import time | |
start = time() | |
for i in range(0, reps): | |
func() | |
end = time() | |
return (end - start) / reps | |
# warm up | |
test_hash_time(hash_a) | |
time = timereps(500, lambda: test_hash_time(hash_a)) | |
print('blake3 : {number:.{digit}f} per second'.format( | |
number=unit_loop / time, | |
digit=2, | |
)) | |
# warm up | |
test_hash_time(hash_b) | |
time = timereps(500, lambda: test_hash_time(hash_b)) | |
print('blake2s: {number:.{digit}f} per second'.format( | |
number=unit_loop / time, | |
digit=2, | |
)) | |
# warm up | |
test_hash_time(hash_c) | |
time = timereps(500, lambda: test_hash_time(hash_c)) | |
print('blake2b: {number:.{digit}f} per second'.format( | |
number=unit_loop / time, | |
digit=2, | |
)) |