-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.py
63 lines (61 loc) · 1.93 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import mgzip
# import gzip as mgzip
import time
def _test():
import sys
import os
# Act like gzip; with -d, act like gunzip.
# The input file is not deleted, however, nor are any other gzip
# options or features supported.
args = sys.argv[1:]
decompress = args and args[0] == "-d"
if decompress:
arg = args[1]
else:
arg = args[0]
# if not args:
# args = ["-"]
if decompress:
tsize = 0
if arg != "-":
# outf = arg + ".dcp"
outf = "/dev/null"
fh = open(outf, "wb")
gh = mgzip.open(arg, "rb")
t0 = time.time()
# gh.show_index()
# data = b"AAA"
chunk_size = 10**7
while True:
data = gh.read(chunk_size)
# data = gh.readline()
if not data:
break
fh.write(data)
tsize += len(data)
# data = gh.readline()
t1 = time.time()
fh.close()
gh.close()
size = tsize/(1024**2)
seconds = t1 - t0
speed = size/seconds
nsize = os.stat(arg).st_size
print("Decompressed {:.2f} MB data in {:.2f} S, Speed: {:.2f} MB/s, Rate: {:.2f} %".format(size, seconds, speed, nsize/tsize*100))
else:
if arg != "-":
outf = arg + ".gz"
fh = open(arg, "rb")
gh = mgzip.open(outf, "wb", compresslevel=6)
data = fh.read()
t0 = time.time()
gh.write(data)
gh.close()
t1 = time.time()
size = len(data)/(1024**2)
seconds = t1 - t0
speed = size/seconds
nsize = os.stat(outf).st_size
print("Compressed {:.2f} MB data in {:.2f} S, Speed: {:.2f} MB/s, Rate: {:.2f} %".format(size, seconds, speed, nsize/len(data)*100))
if __name__ == '__main__':
_test()