Commit 156c7620 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

Compression methods benchmark.

parent fd6bb97d
########################################################################################################################
# Comparison between compression methods.
#
# LZMA is quite slow for compression, but has the highest compression rate and decompression speed.
#
# -- Results:
# [Original] Size: 62964332
# [ZIP_LZMA] Size: 6585510 (10.46% of original)
# [ZIP_LZMA] Compression duration: 0:00:43.131038
# [ZIP_LZMA] Decompression duration: 0:00:00.819297
# [ZIP_STORED] Size: 62964472 (100.00% of original)
# [ZIP_STORED] Compression duration: 0:00:00.173198
# [ZIP_STORED] Decompression duration: 0:00:00.182758
# [ZIP_DEFLATED_1] Size: 13180243 (20.93% of original)
# [ZIP_DEFLATED_1] Compression duration: 0:00:00.679800
# [ZIP_DEFLATED_1] Decompression duration: 0:00:00.387166
# [ZIP_DEFLATED_9] Size: 9551718 (15.17% of original)
# [ZIP_DEFLATED_9] Compression duration: 0:00:07.575646
# [ZIP_DEFLATED_9] Decompression duration: 0:00:00.359863
# [ZIP_BZIP2_1] Size: 7625275 (12.11% of original)
# [ZIP_BZIP2_1] Compression duration: 0:00:03.676536
# [ZIP_BZIP2_1] Decompression duration: 0:00:01.260000
# [ZIP_BZIP2_9] Size: 7416911 (11.78% of original)
# [ZIP_BZIP2_9] Compression duration: 0:00:04.170374
# [ZIP_BZIP2_9] Decompression duration: 0:00:01.792296
import os
import datetime
import zipfile
base_dir = "/homel/ojossoud/_temp/wimcollect/benchmark"
source_filepath = os.path.join(base_dir, "HIDS2194-20200101.dat")
original_size = os.stat(source_filepath).st_size
print("[Original] Size: " + str(original_size))
def compress_decompress(name: str, compression, compression_level):
# Compress
lzma_filepath = os.path.join(base_dir, "HIDS2194-20200101.out")
before = datetime.datetime.now()
zipf = zipfile.ZipFile(lzma_filepath, 'w', compression, compresslevel=compression_level)
zipf.write(source_filepath, arcname=os.path.basename(source_filepath))
zipf.close()
after = datetime.datetime.now()
duration = str(after - before)
lzma_size = os.stat(lzma_filepath).st_size
comp_factor = lzma_size * 100 / original_size
print("[" + name + "] Size: " + str(lzma_size) + " (" + "{:.2f}".format(comp_factor) + "% of original)")
print("[" + name + "] Compression duration: " + duration)
# Decompress
before = datetime.datetime.now()
source_zip = zipfile.ZipFile(lzma_filepath, 'r')
source_zip.extractall(base_dir)
source_zip.close()
after = datetime.datetime.now()
duration = str(after - before)
print("[" + name + "] Decompression duration: " + duration)
compress_decompress("ZIP_LZMA", zipfile.ZIP_LZMA, None)
compress_decompress("ZIP_STORED", zipfile.ZIP_STORED, None)
compress_decompress("ZIP_DEFLATED_1", zipfile.ZIP_DEFLATED, 1)
compress_decompress("ZIP_DEFLATED_9", zipfile.ZIP_DEFLATED, 9)
compress_decompress("ZIP_BZIP2_1", zipfile.ZIP_BZIP2, 1)
compress_decompress("ZIP_BZIP2_9", zipfile.ZIP_BZIP2, 9)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment