Socket creation speed huge difference Python3.7/Python2.7

Refresh

February 2019

Views

11 time

2

I'm trying to create a socket, then connect to the same server until I can't make any connection from my PC and I face a problem : my program is WAY faster with Python 2.7 than with Python 3.7.

Here a minimal example:

import time
import socket

begin = time.time()
socket_list = []

while True:
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(1)
        s.connect(("192.168.2.136", 443))
        socket_list.append(s)
    except:
        print(len(socket_list))
        print(time.time() - begin)
        for sock in socket_list:
            sock.close()
        break

Ouput with Python 3.7:

16307
61.269294023513794

Ouput with Python 2.7:

16297
7.42300009727

Config: Windows 10 (I can put some detail if necessary)

0 answers