Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yeah I always hear people saying how Python is slow.

But in 10 years of Python programming, I see 2 repeated performance anti-patterns:

1) Writing quadratic loops and not realizing it, then it blows up on a biggish data set. This is quite easy to do in Python because people don't realize that "in" on a list and .remove() and so forth do a linear search.

2) Writing Python like Java, where you have tons of indirection, which is slow. People somehow feel naked when they only have to type 10 characters rather than banging out a bunch of boilerplate for a mundane task.

When you're just using basic data structures in an idiomatic way, Python is fast. I think there were some dictionary-heavy benchmarks I saw awhile ago where Python is faster than Go, because its dictionaries are so highly tuned.



> Writing Python like Java, where you have tons of indirection, which is slow

I've actually just introduced one of my younger colleagues (and pretty new to Python, but knowledgeable in C# and Java) to this 8-year old article: http://dirtsimple.org/2004/12/python-is-not-java.html

I remember reading that article back in the day, I had only begun to do stuff in Python for a year or so, and everything seemed so well explained but here I am now instead still spreading the word :) At least some part of it I hope it's done for good, such as "XML is not the answer", which actually brings back "horrific" memories of Zope3.


The person I was responding to sounds likely to make mistake #2.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: