# Pastebin RRBeEcz7 import socket import ssl, time from select import select # SET VARIABLES packet = ["GET https://baroquesoftware.com/index.html HTTP/1.1", "Host: www.baroquesoftware.com", "Connection: Keep-Alive", "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", ""] packet = "\r\n".join(packet) + "\r\n" HOST, PORT = 'baroquesoftware.com', 443 #HOST, PORT = 'localhost', 80 total = [] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) wrappedSocket = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLSv1_1) wrappedSocket.setblocking(0) conn = wrappedSocket.connect_ex((HOST, PORT)) def send_all(sock, v): cur = 0 while True: a, b, c = select([], [wrappedSocket.fileno()], []) try: cur += wrappedSocket.send(v[cur:]) except Exception as e: if isinstance(e, OSError) and e.errno == 2: continue else: raise if cur == len(v): break for k in range(300): # CREATE SOCKET t0 = time.process_time() for i in range(100): # WRAP SOCKET #wrappedSocket = sock # CONNECT AND PRINT REPLY send_all(wrappedSocket, packet.encode("utf8")) #print(packet) l = [] while True: a, b, c = select([wrappedSocket.fileno()], [], [], 0.0) if not a: break r = wrappedSocket.recv(8192) if not r: break l.append(r.decode("utf8")) #print("".join(l)) # CLOSE SOCKET CONNECTION t1 = time.process_time() total.append(t1 - t0) print("%.3f %d req/s" % (t1 - t0, 100./(t1 - t0))) wrappedSocket.close() print("Average: %.3f" % (sum(total)/len(total))) print("Average skipping 10: %.3f" % (sum(total[10:])/len(total[10:])))