benchmarking: update bench_dirnode to be correct and use the shiniest new pyutil.benchutil features concerning what units you measure in

This commit is contained in:
Zooko O'Whielacronx
2010-07-18 21:49:48 -07:00
parent 9b4f412e49
commit 2ebe2c2ff3

View File

@ -35,18 +35,20 @@ class FakeNodeMaker:
def create_from_cap(self, writecap, readcap=None, deep_immutable=False, name=''): def create_from_cap(self, writecap, readcap=None, deep_immutable=False, name=''):
return FakeNode() return FakeNode()
def random_unicode(l): def random_unicode(n=140, b=3, codec='utf-8'):
while True: l = []
while len(l) < n:
try: try:
return os.urandom(l).decode('utf-8') u = os.urandom(b).decode(codec)[0]
except UnicodeDecodeError: except UnicodeDecodeError:
pass pass
else:
l.append(u)
return u''.join(l)
encoding_parameters = {"k": 3, "n": 10} encoding_parameters = {"k": 3, "n": 10}
def random_metadata(): def random_metadata():
d = {} d = {}
d['ctime'] = random.random()
d['mtime'] = random.random()
d['tahoe'] = {} d['tahoe'] = {}
d['tahoe']['linkcrtime'] = random.random() d['tahoe']['linkcrtime'] = random.random()
d['tahoe']['linkmotime'] = random.random() d['tahoe']['linkmotime'] = random.random()
@ -88,7 +90,7 @@ class B(object):
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(0, 10))
self.children.append( (name, self.random_child()) ) self.children.append( (name, self.random_child()) )
def init_for_unpack(self, N): def init_for_unpack(self, N):
@ -109,8 +111,11 @@ class B(object):
(self.init_for_pack, self.pack), (self.init_for_pack, self.pack),
(self.init_for_unpack, self.unpack_and_repack)]: (self.init_for_unpack, self.unpack_and_repack)]:
print "benchmarking %s" % (func,) print "benchmarking %s" % (func,)
benchutil.bench(self.unpack_and_repack, initfunc=self.init_for_unpack, for N in 16, 512, 2048, 16384:
TOPXP=12)#, profile=profile, profresults=PROF_FILE_NAME) print "%5d" % N,
benchutil.rep_bench(func, N, initfunc=initfunc, MAXREPS=20, UNITS_PER_SECOND=1000)
benchutil.print_bench_footer(UNITS_PER_SECOND=1000)
print "(milliseconds)"
def prof_benchmarks(self): def prof_benchmarks(self):
# This requires pyutil >= v1.3.34. # This requires pyutil >= v1.3.34.