# Create read+events (10 sockts): # Without the patch: Best of 25 runs (100000 loops, 10 FDs): 1294 ns per call to epoll.poll() # With the patch: Best of 50 runs (100000 loops, 10 FDs): 1221 ns (-6%) per call to epoll.poll() # # Create read+events (8000 sockts): # Without the patch: Best of 25 runs (10 loops, 16000 FDs): 4.6 ms per call to epoll.poll() # With the patch: Best of 25 runs (10 loops, 16000 FDs): 4.6 ms (same) per call to epoll.poll() # # Don't create events (10 sockets): # Without the patch: Best of 50 runs (100000 loops, 10 FDs): 367 ns per call to epoll.poll() # With the patch: Best of 50 runs (100000 loops, 10 FDs): 343 ns (-7%) per call to epoll.poll() # # Don't create events (1000 sockets): # Without the patch: Best of 50 runs (100000 loops, 1000 FDs): 420 ns per call to epoll.poll() # With the patch: Best of 50 runs (100000 loops, 1000 FDs): 326 ns (-22%) per call to epoll.poll() # # Don't create events (16000 sockets): # Without the patch: Best of 50 runs (100000 loops, 16000 FDs): 422 ns per call to epoll.poll() # With the patch: Best of 50 runs (100000 loops, 16000 FDs): 338 ns (-20%) per call to epoll.poll() import os import select import time import socket #NPAIRS = 5 # number of socketpairs NPAIRS = 500 # number of socketpairs #NPAIRS = 8000 # number of socketpairs NRUN = 25 READ = False # create read events? WRITE = False # create write events? if (READ or WRITE) and NPAIRS > 1000: NLOOP = 10 else: NLOOP = 10**5 socketpairs = [] while len(socketpairs) < NPAIRS: try: r, w = socket.socketpair() except OSError: break socketpairs.append((r, w)) nfds = len(socketpairs) * 2 print("Benchmark with %s FDs (%s socket pairs)" % (nfds, len(socketpairs))) if READ: print("Create read events") if WRITE: print("Create write events") if not(READ or WRITE): print("Don't create events (epoll.poll() always return an empty list)") poller = select.epoll() for r, w in socketpairs: poller.register(r.fileno(), select.EPOLLIN) if WRITE: poller.register(w.fileno(), select.EPOLLOUT) max_events = nfds times = [] for run in range(NRUN): # create socketpairs/2 events if READ: for r, w in socketpairs: w.send(b'hello') start = time.perf_counter() for loop in range(NLOOP): poller.poll(0, max_events) dt = time.perf_counter() - start if READ: for r, w in socketpairs: data = r.recv(1024) assert data == b'hello' times.append(dt / NLOOP) poller.close() dt = min(times) if dt >= 2e-3: dt = "%.1f ms" % (dt * 1e3) elif dt >= 2e-6: dt = "%.1f us" % (dt * 1e6) else: dt = "%.0f ns" % (dt * 1e9) print("Best of %s runs (%s loops, %s FDs): %s per call to epoll.poll()" % (NRUN, NLOOP, nfds, dt)) for r, w in socketpairs: r.close() w.close()