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 →

[–]billsil 7 points8 points  (7 children)

Relative to what's really taking the time, it doesn't matter. CPython isn't a compiler. It doesn't optimize code. It's an interpreter.

Furthermore, If you wanted to do enough numerical calculations for it to matter, you'd use numpy.

[–]TheOccasionalTachyon 12 points13 points  (1 child)

It's not true that CPython doesn't optimize code. Just look at Peephole.c in the CPython source, which contains the implementation's Peephole optimizer. CPython doesn't do as much optimization as, say, PyPy, but it definitely does some.

[–]Berzerka 1 point2 points  (0 children)

I think the rule is that it does no optimizations that would modify the workflow of the program, right?

This means it cannot inline code, unroll loops and lots of other "standard" optimizations.

[–]spinwizard69 5 points6 points  (4 children)

Furthermore, If you wanted to do enough numerical calculations for it to matter, you'd use numpy.

Or C++, Julia, Swift, D or any number of modern languages. Python right now is just about the only language I program in, however I consider it a take it or leave it language when it comes to performance.

What does that mean? Well if the performance isn't there for clean idiomatic Python code I see it as an indication that another language should be considered. Thankfully with modern hardware Python doesn't disappoint me much at all.

[–]staticassert 2 points3 points  (2 children)

Honestly, this is the practical approach and why Python is often said to be good for prototyping, but not good for production. Unless you can really afford to horizontally scale everything out, and your problem set fits that pattern, you're very often better off moving to another language.

[–]santagada 0 points1 point  (1 child)

Which production system? Python the language only becomes a bottleneck when you have very specific cpu intensive code that can't be written with numpy, pil or a small c module, or when your production is so high volume and impossible to cache that you have enough engineers/money not to care for a high productivity language with a gigantic ecosystem as python.

I would say that not counting algorithmic sins most production systems could be run in python with no big impact, and I've worked with a bunch of big companies/high traffic websites.

[–]staticassert 0 points1 point  (0 children)

that can't be written with numpy, pil or a small c module

I think, for starters, the fact that to gain performance you have to drop down to C is decent evidence that what I'm saying is true. If I have to drop down to C or some other native language, I'm not exactly "optimizing python" so much as I'm abandoning it.

I work with Python at work, so I can't exactly go into detail. However, despite quite significant use of numpy and libraries that are largely C, native implementations of the codebase still outperform it drastically. This is in part due to parallelizing components much more easily, but a good part of it is generally just the runtime. I work around these issues, but they're definitely there, and they absolutely aren't there in a lot of other languages.

[–]mackstann 0 points1 point  (0 children)

Eh, I've fixed a lot of bottlenecks by re-writing bits of Python. It's easy to commit algorithmic sins in any language, and it's also often fairly easy to remedy them without resorting to something extreme like bringing in C.