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
#2
Removing the line
s.settimeout(1)
solved the problem, I now have similar performance with Python 2.7 and Python 3.7. Why, I don't know.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to optimize the speed of processing large JSON files in Python without using too sophia2005 3 888 Aug-02-2025, 03:25 PM
Last Post: snippsat
  Is there a difference between Python’s time.sleep and win32api.Sleep? phpjunkie 4 1,965 Sep-21-2024, 05:17 PM
Last Post: aakritiintelligence
  how to find difference between fake driving license or real using python? pjaymn 5 6,078 Jun-14-2024, 07:01 AM
Last Post: Pedroski55
  python difference between sys.exit and exit() mg24 1 6,799 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  dynamic object creation using python gary 7 3,457 Oct-15-2022, 01:35 PM
Last Post: Larz60+
  Increase the speed of a python loop over a pandas dataframe mcva 0 2,403 Jan-21-2022, 06:24 PM
Last Post: mcva
  changing animation speed using buttons in python microwave 1 3,784 Jun-24-2020, 05:21 PM
Last Post: GOTO10
  python 3 find difference between 2 files pd007 2 3,425 May-22-2020, 01:16 AM
Last Post: Larz60+
Question Difference between Python's os.system and Perl's system command Agile741 13 12,375 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 3,968 May-22-2019, 07:20 AM
Last Post: buran

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.