Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic benchmarking works now #104

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions bench/bench_zfec.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from zfec import easyfec, Encoder, filefec
from zfec import easyfec, Encoder, filefec, Decoder
from pyutil import mathutil

import os, sys

from pyutil import benchutil
from time import time

FNAME="benchrandom.data"

Expand All @@ -16,7 +15,7 @@ def donothing(results, reslenthing):
K=3
M=10

d = ""
d = b""
ds = []
easyfecenc = None
fecenc = None
Expand All @@ -30,12 +29,12 @@ def _make_new_rand_data(size, k, m):
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]))
ds[-1] = ds[-1] + b"\x00" * (len(ds[-2]) - len(ds[-1]))
easyfecenc = easyfec.Encoder(k, m)
fecenc = Encoder(k, m)

import sha
hashers = [ sha.new() for i in range(M) ]
from hashlib import sha256
hashers = [ sha256() for i in range(M) ]
def hashem(results, reslenthing):
for i, result in enumerate(results):
hashers[i].update(result)
Expand Down Expand Up @@ -77,26 +76,35 @@ def _encode_data_fec(N):

def bench(k, m):
SIZE = 10**6
MAXREPS = 64
MAXREPS = 1000
# 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 %d bytes %d times in a row..." % (k, m, SIZE, MAXREPS)
print("measuring encoding of data with K=%d, M=%d, encoding %d bytes %d times in a row..." % (k, m, SIZE, MAXREPS))
# for f in [_encode_data_fec, _encode_data_not_really]:
for f in [_encode_data_fec]:
def _init_func(size):
return _make_new_rand_data(size, k, m)
for BSIZE in [SIZE]:
results = benchutil.rep_bench(f, n=BSIZE, initfunc=_init_func, MAXREPS=MAXREPS, MAXTIME=None, UNITS_PER_SECOND=1000000000)
print "and now represented in MB/s..."
print
best = results['best']
mean = results['mean']
worst = results['worst']
print "best: % 4.3f MB/sec" % (10**3 / best)
print "mean: % 4.3f MB/sec" % (10**3 / mean)
print "worst: % 4.3f MB/sec" % (10**3 / worst)
_init_func(BSIZE)
start = time()
for _ in range(MAXREPS):
f(BSIZE)
elapsed = (time() - start) / MAXREPS
print("Average MB/s:", (BSIZE / (1024 * 1024)) / elapsed)

itamarst marked this conversation as resolved.
Show resolved Hide resolved
print("measuring decoding of data with K=%d, M=%d, %d times in a row..." % (k, m, MAXREPS))
blocks = fecenc.encode(ds)
sharenums = list(range(len(blocks)))
decer = Decoder(k, m)
start = time()
for _ in range(MAXREPS):
decer.decode(blocks[:k], sharenums[:k])
assert b"".join(decer.decode(blocks[:k], sharenums[:k]))[:SIZE] == b"".join(ds)[:SIZE]
elapsed = (time() - start) / MAXREPS
itamarst marked this conversation as resolved.
Show resolved Hide resolved
print("Average MB/s:", (sum(len(b) for b in blocks) / (1024 * 1024)) / elapsed)


k = K
m = M
Expand Down
Loading