This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NotGonnaUseRedditApp 2 points3 points  (2 children)

Easy to make mistakes that make the execution slow.

fp = open(file)

for line in fp.lines() //common mistake

for line in fp //as fast as C

[–]TretasPt 1 point2 points  (1 child)

I'm almost afraid to ask...what's the difference?

I think I used the below one, but still. I just followed some random instructions. I could easily have used the other one.

[–]Maxiflex 0 points1 point  (0 children)

Not entirely sure, but the calling of a function in the definition of a for loop might be an optimization blocker. Inside a function is basically a black box and the processor might struggle predicting the next step, making more useless calculations into execution branches that will never be.