From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Fri, 26 Jan 2007 00:33:48 +0000 (-0700)
Subject: add benchmark
X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~317
X-Git-Url: https://git.rkrishnan.org/%5B/COPYING.TGPPL.html?a=commitdiff_plain;h=d893e656df0d5d9acbb80b8c94ed27aaba3c0f53;p=tahoe-lafs%2Ftahoe-lafs.git

add benchmark
---

diff --git a/pyfec/fec/filefec.py b/pyfec/fec/filefec.py
index a2c036ea..d18b69e5 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")
+