Skip to content

Instantly share code, notes, and snippets.

@midnight-wonderer
Created October 4, 2021 14:55
Show Gist options
  • Save midnight-wonderer/9110489f75fde8ae8526d4a72e571dfc to your computer and use it in GitHub Desktop.
Save midnight-wonderer/9110489f75fde8ae8526d4a72e571dfc to your computer and use it in GitHub Desktop.
BLAKE3 vs BLAKE2 for short input message

BLAKE3 vs BLAKE2 benchmark for short input

Observed result

blake3 : 335251.50 per second
blake2s: 715722.22 per second
blake2b: 663446.58 per second

Conclusion from the result

blake2 can run 2x faster than blake3 for short messages

Disclaimer

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,
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment