Get the App
SLTechnology News&Howtos  ›  Development  › 

Why the performance of Python is so powerful

Shulou Source: shulou.com Published: 2022-06-02 21:54:18 11月09日 Update

Why the performance of Python is so powerful, I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

The performance of Python is very powerful, why are the related technologies so powerful? Let's take a look at the relevant technical issues in detail. The question is raised from this brother's BLOG, in his implementation, Python performance has a quite good performance, not only better than the C implementation performance in the post, but also better than the subsequent post in the performance of many C++ implementations.

After many attempts, it is still difficult for me to find an implementation that is better than Python performance. This is not a normal thing, and Python performance is destined to be no better than that of C _ Python. This is because Python is interpreted, and the process of interpretation is bound to consume CPU time, so I looked up the source code of Python to try to find out why Python performance is so good for this task.

The task description is as follows

For a 78W line text file, each line is an Email address, and there are duplicate lines in the file. The task is to generate an Email-free text file from this text file as soon as possible.

There are the following problems to pay attention to

For this large number of string comparisons, using the string comparison function directly is a serious hindrance to performance. IO performance should be noted to use as little memory as possible in my attempt. It was found that the repeated call to ofstream::operatormy took 1687.5000 milliseconds E:\ Workspace\ Temp\ Email > my passed 1718.7500 milliseconds E:\ Workspace\ Temp\ Email > my 1671.8750 milliseconds E:\ Workspace\ Temp\ Email > my 1656.2500 milliseconds E:\ Workspace\ Temp\ Email > py_email.py 2.82014641526 E:\ Workspace\ Temp\ Email > py_email.py 2.74879181572 E:\ Workspace\ Temp\ Email > py_email.py 2.76348586203 E:\ Workspace\ Temp\ Email > dir * .txt 2006-03-28 13:09 19388869 email.txt 2006-03-29 22:51 17779266 email_new.txt (written by py_email.py) 22:50 17779266 email_new_my.txt (written by my.exe) Do you have a way to understand why Python performance is so powerful? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Performance problem power task character string file text algorithm content reason as much as possible technology method more mechanism caching try influence explain Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker Huawei Linux Xiaomi