mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-05-02 17:12:59 +00:00
tests: fix pyflakes warnings in bench_dirnode.py
This commit is contained in:
parent
18922ac618
commit
294c0a6279
@ -36,7 +36,25 @@ def random_unicode(l):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
encoding_parameters = {"k": 3, "n": 10}
|
encoding_parameters = {"k": 3, "n": 10}
|
||||||
def random_fsnode():
|
def random_metadata():
|
||||||
|
d = {}
|
||||||
|
d['ctime'] = random.random()
|
||||||
|
d['mtime'] = random.random()
|
||||||
|
d['tahoe'] = {}
|
||||||
|
d['tahoe']['linkcrtime'] = random.random()
|
||||||
|
d['tahoe']['linkmotime'] = random.random()
|
||||||
|
return d
|
||||||
|
|
||||||
|
PROF_FILE_NAME="bench_dirnode.prof"
|
||||||
|
|
||||||
|
class B(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.children = [] # tuples of (k, v) (suitable for passing to dict())
|
||||||
|
self.packstr = None
|
||||||
|
self.nodemaker = FakeNodeMaker()
|
||||||
|
self.testdirnode = dirnode.DirectoryNode(ContainerNode(), self.nodemaker, uploader=None)
|
||||||
|
|
||||||
|
def random_fsnode(self):
|
||||||
coin = random.randrange(0, 3)
|
coin = random.randrange(0, 3)
|
||||||
if coin == 0:
|
if coin == 0:
|
||||||
cap = uri.CHKFileURI(randutil.insecurerandstr(16),
|
cap = uri.CHKFileURI(randutil.insecurerandstr(16),
|
||||||
@ -56,36 +74,19 @@ def random_fsnode():
|
|||||||
randutil.insecurerandstr(32))
|
randutil.insecurerandstr(32))
|
||||||
n = MutableFileNode(None, None, encoding_parameters, None)
|
n = MutableFileNode(None, None, encoding_parameters, None)
|
||||||
n.init_from_cap(cap)
|
n.init_from_cap(cap)
|
||||||
return dirnode.DirectoryNode(n, nodemaker, uploader=None)
|
return dirnode.DirectoryNode(n, self.nodemaker, uploader=None)
|
||||||
|
|
||||||
def random_metadata():
|
def random_child(self):
|
||||||
d = {}
|
return self.random_fsnode(), random_metadata()
|
||||||
d['ctime'] = random.random()
|
|
||||||
d['mtime'] = random.random()
|
|
||||||
d['tahoe'] = {}
|
|
||||||
d['tahoe']['linkcrtime'] = random.random()
|
|
||||||
d['tahoe']['linkmotime'] = random.random()
|
|
||||||
return d
|
|
||||||
|
|
||||||
def random_child():
|
|
||||||
return random_fsnode(), random_metadata()
|
|
||||||
|
|
||||||
class B(object):
|
|
||||||
def __init__(self):
|
|
||||||
self.children = [] # tuples of (k, v) (suitable for passing to dict())
|
|
||||||
self.packstr = None
|
|
||||||
self.nodemaker = FakeNodeMaker()
|
|
||||||
self.testdirnode = dirnode.DirectoryNode(ContainerNode(), self.nodemaker, uploader=None)
|
|
||||||
|
|
||||||
def init_for_pack(self, N):
|
def init_for_pack(self, N):
|
||||||
for i in xrange(len(self.children), N):
|
for i in xrange(len(self.children), N):
|
||||||
name = random_unicode(random.randrange(1, 9))
|
name = random_unicode(random.randrange(1, 9))
|
||||||
self.children.append( (name, random_child()) )
|
self.children.append( (name, self.random_child()) )
|
||||||
|
|
||||||
def init_for_unpack(self, N):
|
def init_for_unpack(self, N):
|
||||||
global packstr
|
|
||||||
self.init_for_pack(N)
|
self.init_for_pack(N)
|
||||||
packstr = pack(N)
|
self.packstr = self.pack(N)
|
||||||
|
|
||||||
def pack(self, N):
|
def pack(self, N):
|
||||||
return self.testdirnode._pack_contents(dict(self.children[:N]))
|
return self.testdirnode._pack_contents(dict(self.children[:N]))
|
||||||
@ -94,31 +95,31 @@ class B(object):
|
|||||||
return self.testdirnode._unpack_contents(self.packstr)
|
return self.testdirnode._unpack_contents(self.packstr)
|
||||||
|
|
||||||
def unpack_and_repack(self, N):
|
def unpack_and_repack(self, N):
|
||||||
return self.testdirnode._pack_contents(self.testdirnode._unpack_contents(packstr))
|
return self.testdirnode._pack_contents(self.testdirnode._unpack_contents(self.packstr))
|
||||||
|
|
||||||
PROF_FILE_NAME="bench_dirnode.prof"
|
def run_benchmarks(self, profile=False):
|
||||||
|
for (initfunc, func) in [(self.init_for_unpack, self.unpack),
|
||||||
def run_benchmarks(profile=False):
|
(self.init_for_pack, self.pack),
|
||||||
for (initfunc, func) in [(init_for_unpack, unpack),
|
(self.init_for_unpack, self.unpack_and_repack)]:
|
||||||
(init_for_pack, pack),
|
|
||||||
(init_for_unpack, unpack_and_repack)]:
|
|
||||||
print "benchmarking %s" % (func,)
|
print "benchmarking %s" % (func,)
|
||||||
benchutil.bench(unpack_and_repack, initfunc=init_for_unpack,
|
benchutil.bench(self.unpack_and_repack, initfunc=self.init_for_unpack,
|
||||||
TOPXP=12)#, profile=profile, profresults=PROF_FILE_NAME)
|
TOPXP=12)#, profile=profile, profresults=PROF_FILE_NAME)
|
||||||
|
|
||||||
def print_stats():
|
def prof_benchmarks(self):
|
||||||
|
# This requires pyutil >= v1.3.34.
|
||||||
|
self.run_benchmarks(profile=True)
|
||||||
|
|
||||||
|
def print_stats(self):
|
||||||
s = hotshot.stats.load(PROF_FILE_NAME)
|
s = hotshot.stats.load(PROF_FILE_NAME)
|
||||||
s.strip_dirs().sort_stats("time").print_stats(32)
|
s.strip_dirs().sort_stats("time").print_stats(32)
|
||||||
|
|
||||||
def prof_benchmarks():
|
|
||||||
# This requires pyutil >= v1.3.34.
|
|
||||||
run_benchmarks(profile=True)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if '--profile' in sys.argv:
|
if '--profile' in sys.argv:
|
||||||
if os.path.exists(PROF_FILE_NAME):
|
if os.path.exists(PROF_FILE_NAME):
|
||||||
print "WARNING: profiling results file '%s' already exists -- the profiling results from this run will be added into the profiling results stored in that file and then the sum of them will be printed out after this run." % (PROF_FILE_NAME,)
|
print "WARNING: profiling results file '%s' already exists -- the profiling results from this run will be added into the profiling results stored in that file and then the sum of them will be printed out after this run." % (PROF_FILE_NAME,)
|
||||||
prof_benchmarks()
|
b = B()
|
||||||
print_stats()
|
b.prof_benchmarks()
|
||||||
|
b.print_stats()
|
||||||
else:
|
else:
|
||||||
run_benchmarks()
|
b = B()
|
||||||
|
b.run_benchmarks()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user