From: zooko Date: Sat, 5 Mar 2011 22:28:23 +0000 (+0530) Subject: bench: take --k= and --m= options on the cmdline and print out more explanation of... X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/priv/rgr-080307.php?a=commitdiff_plain;h=06a88980be5b99cb72692e4e55542326e3238df4;p=tahoe-lafs%2Fzfec.git bench: take --k= and --m= options on the cmdline and print out more explanation of the output Ignore-this: 52610214e79646140d2d0bef1259808 darcs-hash:c34e32d6a1d82a069562d730f11f3225c5a72c21 --- diff --git a/zfec/bench/bench_zfec.py b/zfec/bench/bench_zfec.py index c3b25ca..fceaed4 100644 --- a/zfec/bench/bench_zfec.py +++ b/zfec/bench/bench_zfec.py @@ -1,7 +1,7 @@ from zfec import easyfec, Encoder, filefec from pyutil import mathutil -import os +import os, sys from pyutil import benchutil @@ -20,17 +20,17 @@ d = "" ds = [] easyfecenc = None fecenc = None -def _make_new_rand_data(size): +def _make_new_rand_data(size, k, m): global d, easyfecenc, fecenc d = os.urandom(size) del ds[:] - ds.extend([None]*K) - blocksize = mathutil.div_ceil(size, K) - for i in range(K): + ds.extend([None]*k) + blocksize = mathutil.div_ceil(size, k) + for i in range(k): ds[i] = d[i*blocksize:(i+1)*blocksize] ds[-1] = ds[-1] + "\x00" * (len(ds[-2]) - len(ds[-1])) - easyfecenc = easyfec.Encoder(K,M) - fecenc = Encoder(K,M) + easyfecenc = easyfec.Encoder(k, m) + fecenc = Encoder(k, m) import sha hashers = [ sha.new() for i in range(M) ] @@ -69,13 +69,25 @@ def _encode_data_easyfec(N): def _encode_data_fec(N): fecenc.encode(ds) -def bench(): +def bench(k, m): # for f in [_encode_file_stringy_easyfec, _encode_file_stringy, _encode_file, _encode_file_not_really,]: # for f in [_encode_file,]: # for f in [_encode_file_not_really, _encode_file_not_really_and_hash, _encode_file, _encode_file_and_hash,]: # for f in [_encode_data_not_really, _encode_data_easyfec, _encode_data_fec,]: + print "measuring encoding of data with K=%d, M=%d, reporting results in nanoseconds per byte after encoding 4 MB..." % (k, m) for f in [_encode_data_fec,]: + def _init_func(size): + return _make_new_rand_data(size, k, m) for BSIZE in [2**22]: - benchutil.rep_bench(f, n=BSIZE, initfunc=_make_new_rand_data, MAXREPS=64, MAXTIME=None) - -bench() + benchutil.rep_bench(f, n=BSIZE, initfunc=_init_func, MAXREPS=64, MAXTIME=None, UNITS_PER_SECOND=1000000000) + benchutil.print_bench_footer(UNITS_PER_SECOND=1000000000) + +k = K +m = M +for arg in sys.argv: + if arg.startswith('--k='): + k = int(arg[len('--k='):]) + if arg.startswith('--m='): + m = int(arg[len('--m='):]) + +bench(k, m)