# Pastebin i1qihBFq import io, socket, time HOST = 'localhost' PORT = 65432 from cffi import FFI ffi = FFI() buf = ffi.buffer(ffi.new("char[8192]"), 8192) class SocketIO(object): def __init__(self, sock): self._s = sock self._buf = ffi.buffer(ffi.new("char[8192]"), 8192) self._cache = [] def readline(self): if self._cache: return self._cache.pop() self._s.recv_into(self._buf, 8192) self._cache.extend(bytes(self._buf).split(b"\n")) self._cache.reverse() l = [] for k in range(30): t0 = time.time() with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) for i in range(100000): #si = socket.SocketIO(s, "rb") #b = io.BufferedReader(si) b = SocketIO(s) while True: x = b.readline() if x is None or x == b'': break tk = time.time() print("%.2f" % (tk - t0)) l.append(tk - t0) # s.write(b"foo\n" * 100) # for k in range(100): # b.readline()