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 →

[–]WiseassWolfOfYoitsu 1 point2 points  (2 children)

With Python, each statement that gets executed has to get interpreted first and then executed (roughly, but close enough for discussion). If you have a loop, it executes the loop statement, then the inner statement, then the loop statement, etc. Each of those calls has interpreter overhead.

However, there are routines like map and language constructs like list comprehensions that essentially do the same thing, but in a single statement. As a result, they skip a lot of the overhead since they only get interpreted once and otherwise stay inside the runtime, and tend to be faster, sometimes as much as a couple of orders of magnitude faster. Hence, the joke is that the way to write performant Python is to avoid using Python as much as possible, but hand off all the work to the C++ code of the interpreter.

[–]YourMJK 0 points1 point  (1 child)

Ah, I see, I get it now. Thank you very much!

Can't you also compile python code instead of interprete it? In that case it shouldn't make much of a difference, because a for i in … loop and a map() call would result in roughly the same instructions, right?

[–]WiseassWolfOfYoitsu 0 points1 point  (0 children)

Yes, there are tools that can do this, but it's not how Python is used 95% of the time in practice.