From d3b870165f7451b50d4fd3c16ce012ab2f7aa2c1 Mon Sep 17 00:00:00 2001 From: zooko Date: Fri, 26 Jan 2007 05:03:48 +0530 Subject: [PATCH] add benchmark darcs-hash:17fbf0713dd2b6615dd817daba3113c5eacb0a53 --- pyfec/fec/filefec.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pyfec/fec/filefec.py b/pyfec/fec/filefec.py index a2c036e..d18b69e 100644 --- a/pyfec/fec/filefec.py +++ b/pyfec/fec/filefec.py @@ -105,3 +105,29 @@ def encode_file_stringy(inf, cb, k, m, chunksize=4096): # print "...finished to encode()" cb(res, indatasize) +def bench(): + FILESIZE=1000000 + CHUNKSIZE=4096 + import os, time + left=FILESIZE + outfile = open("tmpranddata", "wb") + try: + while left: + d = os.urandom(min(left, CHUNKSIZE)) + outfile.write(d) + left -= len(d) + outfile.flush() + outfile = None + infile = open("tmpranddata", "rb") + def cb(s, l): + pass + st = time.time() + encode_file(infile, cb, 25, 100, 4096) + so = time.time() + infile.close() + infile = None + print "Encoded %s byte file in %0.2f seconds, or %0.2f million bytes per second" % (FILESIZE, so-st, FILESIZE/((so-st)*1000000),) + return so-st + finally: + os.remove("tmpranddata") + -- 2.45.2