1 from zfec import easyfec, Encoder, filefec
2 from pyutil import mathutil
6 from pyutil import benchutil
8 FNAME="benchrandom.data"
10 def _make_new_rand_file(size):
11 open(FNAME, "wb").write(os.urandom(size))
13 def donothing(results, reslenthing):
23 def _make_new_rand_data(size):
24 global d, easyfecenc, fecenc
28 blocksize = mathutil.div_ceil(size, K)
30 ds[i] = d[i*blocksize:(i+1)*blocksize]
31 ds[-1] = ds[-1] + "\x00" * (len(ds[-2]) - len(ds[-1]))
32 easyfecenc = easyfec.Encoder(K,M)
36 hashers = [ sha.new() for i in range(M) ]
37 def hashem(results, reslenthing):
38 for i, result in enumerate(results):
39 hashers[i].update(result)
42 filefec.encode_file(open(FNAME, "rb"), donothing, K, M)
44 def _encode_file_stringy(N):
45 filefec.encode_file_stringy(open(FNAME, "rb"), donothing, K, M)
47 def _encode_file_stringy_easyfec(N):
48 filefec.encode_file_stringy_easyfec(open(FNAME, "rb"), donothing, K, M)
50 def _encode_file_not_really(N):
51 filefec.encode_file_not_really(open(FNAME, "rb"), donothing, K, M)
53 def _encode_file_not_really_and_hash(N):
54 filefec.encode_file_not_really_and_hash(open(FNAME, "rb"), donothing, K, M)
56 def _encode_file_and_hash(N):
57 filefec.encode_file(open(FNAME, "rb"), hashem, K, M)
59 def _encode_data_not_really(N):
63 assert len(d) == N == i
66 def _encode_data_easyfec(N):
69 def _encode_data_fec(N):
73 # for f in [_encode_file_stringy_easyfec, _encode_file_stringy, _encode_file, _encode_file_not_really,]:
74 # for f in [_encode_file,]:
75 # for f in [_encode_file_not_really, _encode_file_not_really_and_hash, _encode_file, _encode_file_and_hash,]:
76 # for f in [_encode_data_not_really, _encode_data_easyfec, _encode_data_fec,]:
77 for f in [_encode_data_fec,]:
79 # benchutil.bench(f, initfunc=_make_new_rand_data, TOPXP=8, MAXREPS=256, MAXTIME=64)
80 benchutil.bench(f, initfunc=_make_new_rand_data, TOPXP=25, MAXREPS=256, MAXTIME=64)