# HG changeset patch # User Laman # Date 2017-06-03 22:38:24 # Node ID 802cbad78f7d4d6000dadf09280e7f970e6811d5 # Parent 13d0327a4abb0d8d2dba67d2d4d5bcdc0630f8a7 benchmarking diff --git a/src/benchmark.py b/src/benchmark.py new file mode 100644 --- /dev/null +++ b/src/benchmark.py @@ -0,0 +1,56 @@ +from time import time + +from hashtree import HashTree + + +def timeF(f): + start=time() + f() + end=time() + print((end-start),"s") + + +def fullRead(): + block=True + with open("/home/laman/ext2.img",mode="rb") as f: + while block: + 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 + for i2 in blocks: + if i1+1!=i2: + f.seek(i2*HashTree.BLOCK_SIZE) + 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 + for i2 in blocks: + if i2<=i1+8: + block=f.read(HashTree.BLOCK_SIZE*(i2-i1)) + else: + f.seek(i2*HashTree.BLOCK_SIZE) + block=f.read(HashTree.BLOCK_SIZE) + i1=i2 + + +def shortSockets(): + pass + + +def longSockets(): + pass + + +# timeF(fullRead) # 85.40341448783875 s +# timeF(selectedRead) # 6.774365186691284 s +# timeF(lessSelectedRead) # 5.930811405181885 s