-
Notifications
You must be signed in to change notification settings - Fork 0
/
iotest.py
39 lines (34 loc) · 853 Bytes
/
iotest.py
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
# iotest.py
#
# A test involving I/O performance
def receive_data(s):
msg = bytearray()
while True:
data = s.recv(1024)
if not data:
break
msg.extend(data)
return msg
def spin():
while True:
pass
if __name__ == '__main__':
import threading
import time
import socket
# Launch a background CPU thread
if True:
t = threading.Thread(target=spin)
t.daemon = True
t.start()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
s.bind(("",50000))
s.listen(1)
print("Run iosend.py to send data")
c,a = s.accept()
start = time.time()
msg = receive_data(c)
end = time.time()
print(end-start)
print("{:0.3f} Bytes/sec".format(len(msg)/(end-start)))