Speed up my program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Speed up my program

In general, how can I speed up my python program ?

21st May 2017, 7:41 AM
mohammad ammar
mohammad ammar - avatar
1 Answer
+ 1
It depends what it's doing to be honest. General rule of thumb: >Use arrays where possible. >When searching for something in anything, be that an array or list, some searching methods are more efficient than others for certain things and list sizes. i.e. linear search, dividing into chunks, etc. >If you have multiple loops iterating the same list. If possible, try reducing the amount to fewer or single if possible for the task. I see this a lot. >Use python built-in functions where possible instead of making your own. Chances are, the built in function is more efficient. This is up for debate, but generally speaking they are, and this is part of the convenience of python. >If you're gonna open a file. Do it only once if possible. Save it to a list, array, dictionary, etc if you need to revisit the information. Those are just extremely straight forward ones at the top of my head.
21st May 2017, 8:13 AM
Sapphire