diff --git a/src/benchmark.py b/src/benchmark.py --- a/src/benchmark.py +++ b/src/benchmark.py @@ -6,49 +6,49 @@ from hashtree import HashTree def timeF(f): - start=time() + start = time() f() - end=time() - print((end-start),"s") + end = time() + print((end-start), "s") def fullRead(): - block=True - with open("/home/laman/ext2.img",mode="rb") as f: + block = True + with open("/home/laman/ext2.img", mode="rb") as f: while block: - block=f.read(HashTree.BLOCK_SIZE) + block = f.read(HashTree.BLOCK_SIZE) def selectedRead(): with open("/home/laman/blocks.txt") as f: - blocks=[int(x) for x in f] - with open("/home/laman/ext2.img",mode="rb") as f: - i1=-1 + blocks = [int(x) for x in f] + with open("/home/laman/ext2.img", mode="rb") as f: + i1 = -1 for i2 in blocks: if i1+1!=i2: f.seek(i2*HashTree.BLOCK_SIZE) - block=f.read(HashTree.BLOCK_SIZE) - i1=i2 + block = f.read(HashTree.BLOCK_SIZE) + i1 = i2 def lessSelectedRead(): with open("/home/laman/blocks.txt") as f: - blocks=[int(x) for x in f] - with open("/home/laman/ext2.img",mode="rb") as f: - i1=-1 + blocks = [int(x) for x in f] + with open("/home/laman/ext2.img", mode="rb") as f: + i1 = -1 for i2 in blocks: if i2<=i1+8: - block=f.read(HashTree.BLOCK_SIZE*(i2-i1)) + block = f.read(HashTree.BLOCK_SIZE*(i2-i1)) else: f.seek(i2*HashTree.BLOCK_SIZE) - block=f.read(HashTree.BLOCK_SIZE) - i1=i2 + block = f.read(HashTree.BLOCK_SIZE) + i1 = i2 def shortSockets(): def _server(): - serverSock=socket.socket(socket.AF_INET, socket.SOCK_STREAM) - serverSock.bind(("",12329)) + serverSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + serverSock.bind(("", 12329)) serverSock.listen(1) for i in range(10000): @@ -61,7 +61,7 @@ def shortSockets(): def _client(): for i in range(10000): - sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("127.0.0.1", 12329)) with sock.makefile(mode="rb") as fr, sock.makefile(mode="wb") as fw: fw.write(b"x"*4096+b"\n") @@ -69,9 +69,9 @@ def shortSockets(): sock.shutdown(socket.SHUT_RDWR) sock.close() - s=threading.Thread(target=_server) + s = threading.Thread(target=_server) s.start() - c=threading.Thread(target=_client) + c = threading.Thread(target=_client) c.start() s.join() c.join() @@ -79,8 +79,8 @@ def shortSockets(): def longSockets(): def _server(): - serverSock=socket.socket(socket.AF_INET, socket.SOCK_STREAM) - serverSock.bind(("",12330)) + serverSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + serverSock.bind(("", 12330)) serverSock.listen(1) sock, address = serverSock.accept() @@ -93,7 +93,7 @@ def longSockets(): serverSock.close() def _client(): - sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("127.0.0.1", 12330)) with sock.makefile(mode="rb") as fr, sock.makefile(mode="wb") as fw: for i in range(10000): @@ -102,9 +102,9 @@ def longSockets(): sock.shutdown(socket.SHUT_RDWR) sock.close() - s=threading.Thread(target=_server) + s = threading.Thread(target=_server) s.start() - c=threading.Thread(target=_client) + c = threading.Thread(target=_client) c.start() s.join() c.join()