RE: Python Code Speed Improvement

You are viewing a single comment's thread from:

Python Code Speed Improvement

in python •  7 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.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

...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?