open_sockets: finer grained timing.
authorEmil Mikulic <emikulic@gmail.com>
Sun, 9 Dec 2018 14:10:06 +0000 (01:10 +1100)
committerEmil Mikulic <emikulic@gmail.com>
Mon, 10 Dec 2018 10:03:17 +0000 (21:03 +1100)
devel/open_sockets.py

index ddf94aa..51670bd 100755 (executable)
@@ -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)