Changeset - 802cbad78f7d
[Not reviewed]
default
0 0 1
Laman - 8 years ago 2017-06-03 22:38:24

benchmarking
1 file changed with 56 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/benchmark.py
Show inline comments
 
new file 100644
 
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
0 comments (0 inline, 0 general)