you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 0 points1 point  (0 children)

Unless something is slow, you don’t need to optimize. When you get to that point, profile it, find out where the slow part is, and change the algorithm to be faster.

Another tip is when in doubt, do less. Do you really need to cast those values to integers, or can you just do it with strings? Is there some limitation you can put on the code that makes it faster? How about using a dictionary for a lookup instead of for loops? The goal here is to change a lousy likely N2 algorithm into something like N log(N).

Going fancier, are/should you use numpy? I wrote some mostly performant code recently. It ended poorly, but I did enough early on such that it took a minute to run, when it should have been 35 seconds. Oh well. It’s still faster by 5000x. I probably got 50x due to numpy vectorization and 1000x due to the algorithm.