You are viewing a single comment's thread from:

RE: Python Code Speed Improvement

in #python7 years ago

Yes but it matters to me though, I was analyzing the market and speed is very crucial, a default calculation takes like 2 hours.

Besides the long string can be automatically written too:

string="sum=array[0]"
for i in range(1,9+1):
       string+="+array["+str(i)+"]"

print (string)

This way we avoid typos and mistakes.

Sort:  

...and then you'd have to eval that long string to get an array which would be even slower, not to say completely unsafe 😉

If your calculation takes 2 hours, then I'd say replacing for loops with manually typed array accesses is not the best place to optimize. Most likely something else takes long to finish.

Have you tried profiling your code?