]> git.rkrishnan.org Git - tahoe-lafs/zfec.git/commitdiff
pyfec: move benchmark code from test_pyfec.py into the new bench_pyfec.py and add...
authorzooko <zooko@zooko.com>
Sat, 27 Jan 2007 02:15:49 +0000 (07:45 +0530)
committerzooko <zooko@zooko.com>
Sat, 27 Jan 2007 02:15:49 +0000 (07:45 +0530)
darcs-hash:9f6c7663a2c127170c07aedb3317d42b6eaae6aa

pyfec/fec/filefec.py
pyfec/fec/test/bench_pyfec.py [new file with mode: 0644]

index 72a15adbabb5fb9cf88325adc7ed34dca4012560..8acc0c9bf8901c61faa7b0e4eadbfbac4c97f5fa 100644 (file)
@@ -202,30 +202,3 @@ def encode_file_not_really(inf, cb, k, m, chunksize=4096):
         # res = enc.encode(l)
         # print "...finished to encode()"
         cb(l, 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")
-
diff --git a/pyfec/fec/test/bench_pyfec.py b/pyfec/fec/test/bench_pyfec.py
new file mode 100644 (file)
index 0000000..a8719f5
--- /dev/null
@@ -0,0 +1,81 @@
+# pyfec -- fast forward error correction library with Python interface
+# 
+# Copyright (C) 2007 Allmydata, Inc.
+# Author: Zooko Wilcox-O'Hearn
+# mailto:zooko@zooko.com
+# 
+# This file is part of pyfec.
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+import fec
+
+import array
+
+def bench_encode_to_files_shuffle_decode_from_files():
+    FILESIZE=1000000
+    CHUNKSIZE=4096
+    K=25
+    M=100
+    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")
+        st = time.time()
+        fec.filefec.encode_to_files(infile, "testshare", K, M)
+        so = time.time()
+        print "Encoded %s byte file into %d share files in %0.2f seconds, or %0.2f million bytes per second" % (FILESIZE, M, so-st, FILESIZE/((so-st)*1000000),)
+        enctime = so-st
+        recoveredfile = open("tmpranddata-recovered", "wb")
+        st = time.time()
+        fec.filefec.decode_from_files(recoveredfile, "testshare", K, M)
+        so = time.time()
+        print "Encoded %s byte file from %d share files in %0.2f seconds, or %0.2f million bytes per second" % (FILESIZE, K, so-st, FILESIZE/((so-st)*1000000),)
+        return enctime + (so-st)
+    finally:
+        # os.remove("tmpranddata")
+        pass
+
+def bench_read_encode_and_drop():
+    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()
+        fec.filefec.encode_file(infile, cb, 25, 100, 4096)
+        so = time.time()
+        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")
+