Files
@ d76b98d421ae
Branch filter:
Location: Morevna/src/benchmark.py - annotation
d76b98d421ae
2.6 KiB
text/x-python
enhanced stats
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | 802cbad78f7d 2adb8e927e34 2adb8e927e34 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 802cbad78f7d 802cbad78f7d 802cbad78f7d 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 2adb8e927e34 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 802cbad78f7d 2adb8e927e34 2adb8e927e34 2adb8e927e34 | from time import time
import socket
import threading
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():
def _server():
serverSock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSock.bind(("",12329))
serverSock.listen(1)
for i in range(10000):
sock, address = serverSock.accept()
with sock.makefile(mode="rb") as fr, sock.makefile(mode="wb") as fw:
fr.readline()
sock.shutdown(socket.SHUT_RDWR)
sock.close()
serverSock.close()
def _client():
for i in range(10000):
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")
fw.flush()
sock.shutdown(socket.SHUT_RDWR)
sock.close()
s=threading.Thread(target=_server)
s.start()
c=threading.Thread(target=_client)
c.start()
s.join()
c.join()
def longSockets():
def _server():
serverSock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSock.bind(("",12330))
serverSock.listen(1)
sock, address = serverSock.accept()
with sock.makefile(mode="rb") as fr, sock.makefile(mode="wb") as fw:
for i in range(10000):
fr.readline()
sock.shutdown(socket.SHUT_RDWR)
sock.close()
serverSock.close()
def _client():
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):
fw.write(b"x"*4096+b"\n")
fw.flush()
sock.shutdown(socket.SHUT_RDWR)
sock.close()
s=threading.Thread(target=_server)
s.start()
c=threading.Thread(target=_client)
c.start()
s.join()
c.join()
# timeF(fullRead) # 85.40341448783875 s
# timeF(selectedRead) # 6.774365186691284 s
# timeF(lessSelectedRead) # 5.930811405181885 s
# timeF(shortSockets) # 3.928339719772339 s
# timeF(longSockets) # 0.15576839447021484 s
|