Python is readable

Roy Smith roy at panix.com
Thu Mar 15 16:14:02 CET 2012


In article <mailman.678.1331821755.3037.python-list at python.org>,
 Chris Angelico <rosuav at gmail.com> wrote:

> I use gcc/g++ with most of the new features enabled. There's some
> pretty handy features in it. Frankly, though, if I'd known about
> Cython when I started the current project, I would have argued to
> write it all in Python and Cify (is that a word?) the most
> performance-critical sections afterwards, instead of writing it in
> C++.

+1.

With the exception of the client-side javascript, virtually 100% of the 
application code behind songza.com is python.  We use django, tornado, 
and gunicorn (all pure python).  The ORM layer (mongoengine) is pure 
python.  Of course, there's plenty of C/C++ code in the database 
(MongoDB), HTTP proxies (nginx and haproxy), and search engine (Xapian), 
but the core application code is all python.  About 80,000 lines worth.

Every time we look at performance, we discover the same thing.  The time 
spent running python code is insignificant.  It's all about network I/O 
and database queries.  The only time we ever see any significant time 
running python code is when we do something stupid and write some O(n^2) 
code that can be replaced by a more appropriate algorithm.

While it's nice to know that we've got the ability to write extensions 
in C, not once have we ever felt the need.  I suppose if you're running 
a CPU-bound application, that might not be the case, but surprisingly 
few applications really are compute bound these days.

I had an interesting experience the other day.  We had a job applicant 
implement one of our coding tests in Java.  It's a data mining exercise 
where you need to generate some summary statistics from a 700,000 line 
log file we give you.  My Python version takes under a second.  His Java 
version came up with the right numbers but took 2 minutes.  I looked at 
his code and didn't any any obvious problem.  It turned out he used a 
regex that started with '.*', and apparently the Java regex library 
implements that badly.  Eliminating the leading '.*' got his Java 
running in the same time as my Python.



More information about the Python-list mailing list