From: zooko Date: Thu, 9 Aug 2007 17:19:13 +0000 (+0530) Subject: zfec: add benchmark utility X-Git-Url: https://git.rkrishnan.org/index.html?a=commitdiff_plain;h=f5c93da2e4d19ebf8079b763d37243e3e70dcf37;p=tahoe-lafs%2Fzfec.git zfec: add benchmark utility darcs-hash:8b6138c421d51a120cda97674c16333abf2448b4 --- diff --git a/zfec/bench/bench_zfec.py b/zfec/bench/bench_zfec.py new file mode 100644 index 0000000..7097d20 --- /dev/null +++ b/zfec/bench/bench_zfec.py @@ -0,0 +1,46 @@ +from zfec import filefec + +import os + +from pyutil import benchutil + +FNAME="benchrandom.data" + +def _make_new_rand_file(size): + open(FNAME, "wb").write(os.urandom(size)) + +def donothing(results, reslenthing): + pass + +import sha +hashers = [ sha.new() for i in range(100) ] +def hashem(results, reslenthing): + for i, result in enumerate(results): + hashers[i].update(result) + +def _encode_file(N): + filefec.encode_file(open(FNAME, "rb"), donothing, 25, 100) + +def _encode_file_stringy(N): + filefec.encode_file_stringy(open(FNAME, "rb"), donothing, 25, 100) + +def _encode_file_stringy_easyfec(N): + filefec.encode_file_stringy_easyfec(open(FNAME, "rb"), donothing, 25, 100) + +def _encode_file_not_really(N): + filefec.encode_file_not_really(open(FNAME, "rb"), donothing, 25, 100) + +def _encode_file_not_really_and_hash(N): + filefec.encode_file_not_really_and_hash(open(FNAME, "rb"), donothing, 25, 100) + +def _encode_file_and_hash(N): + filefec.encode_file(open(FNAME, "rb"), hashem, 25, 100) + +def bench(): + # 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,]: + print f + benchutil.bench(f, initfunc=_make_new_rand_file, TOPXP=23, MAXREPS=128, MAXTIME=64) + +# bench() diff --git a/zfec/zfec/filefec.py b/zfec/zfec/filefec.py index 1419ae8..30985a9 100644 --- a/zfec/zfec/filefec.py +++ b/zfec/zfec/filefec.py @@ -336,6 +336,72 @@ def encode_file(inf, cb, k, m, chunksize=4096): res = enc.encode(l) cb(res, indatasize) +import sha +def encode_file_not_really(inf, cb, k, m, chunksize=4096): + enc = zfec.Encoder(k, m) + l = tuple([ array.array('c') for i in range(k) ]) + indatasize = k*chunksize # will be reset to shorter upon EOF + eof = False + ZEROES=array.array('c', ['\x00'])*chunksize + while not eof: + # This loop body executes once per segment. + i = 0 + while (i