Skip to content

Instantly share code, notes, and snippets.

@nfl0
Created May 1, 2023 23:20
Show Gist options
  • Save nfl0/b4259c0c072372477c0a1f5a5cae9bd6 to your computer and use it in GitHub Desktop.
Save nfl0/b4259c0c072372477c0a1f5a5cae9bd6 to your computer and use it in GitHub Desktop.
import time
from blake3 import blake3
import hashlib
# Data for benchmarking
data = b"some data to hash" * 1000000
# BLAKE3 hashing and benchmarking
start_time_blake3 = time.time()
hasher_blake3 = blake3()
hasher_blake3.update(data)
hash_digest_blake3 = hasher_blake3.digest()
end_time_blake3 = time.time()
# SHA256 hashing and benchmarking
start_time_sha256 = time.time()
hasher_sha256 = hashlib.sha256()
hasher_sha256.update(data)
hash_digest_sha256 = hasher_sha256.digest()
end_time_sha256 = time.time()
# Results
print("BLAKE3 hash:", hash_digest_blake3.hex())
print("SHA256 hash:", hash_digest_sha256.hex())
print("BLAKE3 time: {:.6f} seconds".format(end_time_blake3 - start_time_blake3))
print("SHA256 time: {:.6f} seconds".format(end_time_sha256 - start_time_sha256))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment