Created
June 27, 2018 07:26
-
-
Save komuw/79696cd0b212163219ccb94073144fb6 to your computer and use it in GitHub Desktop.
different compression sizes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pre-requistes: | |
# pip install brotli ; from https://github.com/google/brotli/tree/master/python | |
# pip install zstandard ; from https://github.com/indygreg/python-zstandard | |
# pip install python-lzo ; from https://github.com/jd-boyd/python-lzo | |
# zlib is in the python stdlib | |
import json | |
import zlib | |
import brotli | |
import zstandard | |
import lzo | |
original_session = json.dumps({"key": "value"}) * 4000 # this creates a session that is 64KB. | |
zlib_compressed_session = zlib.compress(original_session, 9) | |
cctx_normal = zstandard.ZstdCompressor(level=22) | |
zstandard_compressed_session = cctx_normal.compress(original_session) | |
lzo_compressed_session = lzo.compress(original_session) | |
brotli_compressed_session = brotli.compress(original_session, quality=11) | |
print "original_session size:", len(original_session) | |
print "zlib_compressed_session size:", len(zlib_compressed_session) | |
print "lzo_compressed_session size:", len(lzo_compressed_session) | |
print "zstandard_compressed_session size:", len(zstandard_compressed_session) | |
print "brotli_compressed_session size:", len(brotli_compressed_session)``` | |
# Results: | |
`original_session size: 64000` | |
`zlib_compressed_session size: 166` | |
`lzo_compressed_session size: 342` | |
`zstandard_compressed_session size: 35` | |
`brotli_compressed_session size: 34` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this creates a session that lends itself very well for compression(because it contains a lot of repeated data), so we should repeat this experiment with session data that has more random data in it.