Skip to content

Instantly share code, notes, and snippets.

@i3p9
Created November 17, 2021 19:30
Show Gist options
  • Save i3p9/a7bc18cc145f81d5d4da26991eab8217 to your computer and use it in GitHub Desktop.
Save i3p9/a7bc18cc145f81d5d4da26991eab8217 to your computer and use it in GitHub Desktop.
Python Compression Timer in SS
import zipfile, time
def DeflateZip(locfile,loczipDef):
start = time.time()
zipDef = zipfile.ZipFile(loczipDef, "w", zipfile.ZIP_DEFLATED)
zipDef.write (locfile)
zipDef.close()
print(f'Deflate: {time.time() - start}')
def Bzip2Zip(locfile,loczipBz):
start = time.time()
zipBz = zipfile.ZipFile(loczipBz, "w", zipfile.ZIP_BZIP2)
zipBz.write (locfile)
zipBz.close()
print(f'BZIP2: {time.time() - start}')
def LzmaZip(locfile,loczipLzma):
start = time.time()
zipLzma = zipfile.ZipFile(loczipLzma, "w", zipfile.ZIP_BZIP2)
zipLzma.write (locfile)
zipLzma.close()
print(f'Lzma: {time.time() - start}')
locfile = "file.pdf"
loczipDef = "zipped_deflate.zip"
loczipBz = "zipped_bzip2.zip"
loczipLzma = "zipped_lzma.zip"
DeflateZip(locfile,loczipDef)
Bzip2Zip(locfile,loczipBz)
LzmaZip(locfile,loczipLzma)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment