Skip to content

Instantly share code, notes, and snippets.

@andiradulescu
Created September 9, 2024 15:12
Show Gist options
  • Save andiradulescu/251c72c46b9ebe196631cfdd1ce86cf1 to your computer and use it in GitHub Desktop.
Save andiradulescu/251c72c46b9ebe196631cfdd1ce86cf1 to your computer and use it in GitHub Desktop.
import lzma
import time
def benchmark_lzma_decompressor(compressed_data):
# Start the timer
start_time = time.time()
# Create an LZMADecompressor object
decompressor = lzma.LZMADecompressor()
# Perform decompression
try:
decompressed_data = decompressor.decompress(compressed_data)
except lzma.LZMAError as e:
print(f"Decompression error: {e}")
return None
# Stop the timer
end_time = time.time()
# Calculate the time taken
time_taken = end_time - start_time
print(f"Time taken to decompress: {time_taken:.6f} seconds")
return decompressed_data
# Sample compressed data (replace this with your actual compressed data)
compressed_data = lzma.compress(b"Test data to compress and benchmark" * 1000)
# Call the benchmark function
benchmark_lzma_decompressor(compressed_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment