Python Forum
Socket creation speed difference Python 2.7 / Python 3.7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Socket creation speed difference Python 2.7 / Python 3.7
#1
Hello,

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:

# client.py

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(("127.0.0.1", 65432))
        socket_list.append(s)
    except:
        print(len(socket_list))
        print(time.time() - begin)
        for sock in socket_list:
            sock.close()
        break
# server.py

import socket 

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1", 65432))
s.listen()
while True:
    s.accept()


Ouput with Python 3.7 client side and Python 3.7 server side:

16298
32.764869928359985

Ouput with Python 2.7 client side and Python 3.7 server side:

16297
1.86599993706

OS: Windows 10
Reply


Messages In This Thread
Socket creation speed difference Python 2.7 / Python 3.7 - by PiAil - Feb-13-2019, 09:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 1,927 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  dynamic object creation using python gary 7 1,371 Oct-15-2022, 01:35 PM
Last Post: Larz60+
  Increase the speed of a python loop over a pandas dataframe mcva 0 1,358 Jan-21-2022, 06:24 PM
Last Post: mcva
  how to find difference between fake driving license or real using python? pjaymn 2 2,640 Dec-20-2020, 08:41 PM
Last Post: jefsummers
  changing animation speed using buttons in python microwave 1 2,162 Jun-24-2020, 05:21 PM
Last Post: GOTO10
  python 3 find difference between 2 files pd007 2 2,232 May-22-2020, 01:16 AM
Last Post: Larz60+
Question Difference between Python's os.system and Perl's system command Agile741 13 6,989 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Python Script to Produce Difference Between Files and Resolve DNS Query for the Outpu sultan 2 2,580 May-22-2019, 07:20 AM
Last Post: buran
  python 2D array creation and print issue developerbrain 5 2,895 May-15-2019, 01:38 PM
Last Post: developerbrain
  python how to find difference between two values hare 1 6,492 Jan-14-2019, 10:18 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020