On python2.7
it seems like a problem like your data
data for compression must be of type 'str'
import gzip import json import lz4 import time with gzip.GzipFile('data.gz','w') as fid_gz: with open('data.json','r') as fid_json:
even if gzip compression
gzip.zlib.compress(json_str,9)
even if lz4 compression
lz4.block.compress(json_str)
and the time check will be
# set start time st = time.time()
On python3.5
the difference between python2.7 and python 3 is the type of your data to compress
data for compression should be "byte" types through bytes ()
when creating the .gz file
with gzip.GzipFile('data.gz','w') as fid_gz: with open('data.json','r') as fid_json: json_dict = json.load(fid_json) json_str = str(json_dict)
or just compress with gzip.compress (data, compresslevel = 9)
# 'data' takes bytes gzip.compress(json_bytes)
or just compress with zlib.compress (bytes, level = -1, /)
gzip.zlib.compress(json_bytes,9)
or just compress with lz4.bloc.compress (source, compression = 0)
# 'source' takes both 'str' and 'byte' lz4.block.compress(json_str) lz4.block.compress(json_bytes)
Measurement time depends on your intention.
amuses