/usr/lib/python2.7/dist-packages/fabio/test/profile_compressed.py is in python-fabio 0.3.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | """
Benchmark the bz2 and gzip modules compared to their system counterparts
"""
from __future__ import print_function
import cProfile, os, time, random, gzip, bz2, struct, sys
try:
import pstats
except:
print("Your package manager is probably teasing you")
print("try sudo apt-get install python-profiler")
sys.exit()
print("Setting up")
npts = int(1e6)
data = [ random.random() for i in range(npts) ]
sdata = struct.pack("d"*npts, *tuple(data))
open("prof.dat", "wb").write(sdata)
open("prof2.dat", "wb").write(" "*npts * 8)
os.system("gzip -c prof.dat > prof.dat.gz")
os.system("bzip2 -c prof.dat > prof.dat.bz2")
os.system("gzip -c prof2.dat > prof2.dat.gz")
os.system("bzip2 -c prof2.dat > prof2.dat.bz2")
print("Done setup")
sys.stdout.flush()
def tst(fobj, fname):
"""test"""
fo = fobj(fname, "rb")
fo.read()
return
print("Python gzip module")
start = time.time()
cProfile.run("tst(gzip.GzipFile, 'prof.dat.gz')", "gzstats")
p = pstats.Stats("gzstats")
p.strip_dirs().sort_stats(-1).print_stats()
del p
print("Python bz2 module")
cProfile.run("tst(bz2.BZ2File, 'prof.dat.bz2')", "bz2stats")
p = pstats.Stats("bz2stats")
p.strip_dirs().sort_stats(-1).print_stats()
del p
def tstsys(cmd):
""" test system"""
fo = os.popen(cmd, "rb")
fo.read()
return
print("System gzip")
cProfile.run("tstsys('gzip -cd prof.dat.gz')", "gzosstats")
p = pstats.Stats("gzosstats")
p.strip_dirs().sort_stats(-1).print_stats()
del p
print("System bz2")
cProfile.run("tstsys('bzip2 -cd prof.dat.bz2')", "bz2osstats")
p = pstats.Stats("bz2osstats")
p.strip_dirs().sort_stats(-1).print_stats()
del p
import timeit
cl = ["ret = gzip.GzipFile( 'prof.dat.gz' ,'rb').read()",
"ret = os.popen( 'gzip -dc prof.dat.gz' ,'rb').read()",
"ret = bz2.BZ2File( 'prof.dat.bz2','rb').read()",
"ret = os.popen( 'bzip2 -dc prof.dat.bz2','rb').read()",
"ret = gzip.GzipFile( 'prof2.dat.gz' ,'rb').read()",
"ret = os.popen( 'gzip -dc prof2.dat.gz' ,'rb').read()",
"ret = bz2.BZ2File( 'prof2.dat.bz2','rb').read()",
"ret = os.popen('bzip2 -dc prof2.dat.bz2','rb').read()",
]
if sys.platform != "win32":
cl.append("ret = os.popen( 'gzip -dc prof.dat.gz' ,'rb',2**20).read()")
cl.append("ret = os.popen( 'bzip2 -dc prof.dat.bz2','rb',2**20).read()")
cl.append("ret = os.popen( 'gzip -dc prof2.dat.gz' ,'rb',2**20).read()")
cl.append("ret = os.popen(' bzip2 -dc prof2.dat.bz2','rb',2**20).read()")
for s in cl:
t = timeit.Timer(s, setup="import os, gzip, bz2")
print("%s\t:\t%s" % (s, t.timeit(5) / 5.))
# Finally - shell version
if sys.platform == 'win32':
start = time.time()
s = "gzip -cd prof.dat.gz > junk"
os.system(s)
print("%s\t:\t%s seconds via shell" % (s, time.time() - start))
start = time.time()
s = "bzip2 -cd prof.dat.bz2 > junk"
os.system(s)
print("%s\t:\t%s seconds via shell" % (s, time.time() - start))
start = time.time()
s = "gzip -cd prof2.dat.gz > junk"
os.system(s)
print("%s\t:\t%s seconds via shell" % (s, time.time() - start))
start = time.time()
s = "bzip2 -cd prof2.dat.bz2 > junk"
os.system(s)
print("%s\t:\t%s seconds via shell" % (s, time.time() - start))
os.remove("junk")
else:
sys.stdout.flush()
s = "time gzip -cd prof.dat.gz > /dev/null"
print("Time shell gzip: %s" % s)
os.system(s)
sys.stdout.flush()
s = "time bzip2 -cd prof.dat.bz2 > /dev/null"
print("Time shell bzip2: %s" % s)
os.system(s)
sys.stdout.flush()
s = "time gzip -cd prof2.dat.gz > /dev/null"
print("Time shell gzip: %s" % s)
os.system(s)
sys.stdout.flush()
s = "time bzip2 -cd prof2.dat.bz2 > /dev/null"
print("Time shell bzip2: %s" % s)
os.system(s)
|