Search code examples
pythonperformanceimplementation

Floating-point efficiency of Python library function implementations


I've seen various answers to the ball collision detection question explaining why sqrt operations are slow, why absolute value operations are fast on floating ponts etc. How can I find out which operations are expensive and which are not?

Basically, I'm looking for a resource where I can learn about the implementation of all the python library functions. When people are saying those things they aren't actually thinking about how that stuff is implemented in C are they?

Thanks, looking to learn more about implementation details on this slick language.


Solution

  • Python is, like any language, translated to machine code and then run. So yes, they could be talking about low-level implementation details.

    Anyway, the best way to learn about speed implementation of the various Python functions is taking a look in the source code.

    Have fun!

    EDIT: This tip actually applies to any open source project I worked with: Got a problem? Take a look at the source code and you should be fine.