open_sockets: finer grained timing.

This commit is contained in:
Emil Mikulic 2018-12-10 01:10:06 +11:00
parent 744bac5cb8
commit e5ce7390c3

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
# Opens sockets until they run out.
import sys, socket
from time import time
def main():
request = b'GET /darkhttpd.c HTTP/1.0\r\n'
@ -9,12 +10,14 @@ def main():
first = True
while True:
try:
s = socket.socket()
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
s.connect(("", 8080))
s.send(request)
socks.append(s)
print(len(socks), 'sockets open')
t0 = time(); s = socket.socket()
t1 = time(); s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
t2 = time(); s.connect(("", 8080))
t3 = time(); s.send(request)
t4 = time(); socks.append(s)
t5 = time()
print('%d sockets open, %f sock, %f setsockopt, %f connect, %f send, %f append' % (
len(socks), t1-t0, t2-t1, t3-t2, t4-t3, t5-t4))
except Exception as e:
if first:
print(e)