Python is not bad ;-)

Chris Angelico rosuav at
Thu Apr 30 12:52:03 CEST 2015

On Thu, Apr 30, 2015 at 8:16 PM, Marko Rauhamaa <marko at> wrote:
> Ben Finney <ben+python at>:
>> The latter is not a property of Python; a programming language doesn't
>> have runtime performance. Rather, runtime performance is a property of
>> some specific *implementation* — that is, the runtime Python machine.
>> There are numerous Python runtimes, and they have different
>> performance characteristics on different hardware and operating
>> systems.
> Still, Python has features that defy effective optimization. Most
> notably, Python's dot notation translates into a hash table lookup -- or
> worse.
> I currently carry three clubs in my professional golf bag: bash, python
> and C. Java is a great programming language, but Python and C manage
> everything Java would be useful for.

(I carry a lot more clubs in my bag. The Ace of Clubs for me is Pike,
but Python comes in a close second; both are decently high
performance, quick to write code in, and come with extensive standard
libraries. Any bash script that grows to more than a page or so of
code usually finds itself rewritten in Python or Pike; C is mainly for
writing high level programming languages in.)

Most of the programs that I write spend their time on work far more
serious than looking up names in dictionaries. For instance, one of my
programs [1] shells out to avconv and sox to do a bunch of big file
conversions, doing its best to fill up my hard disk (eighty-odd gig of
intermediate files is a good start), and ultimately producing one
hefty video file. Another that I contribute heavily to [2] uses lame
to manipulate a bunch of .MP3 files and, ultimately, stream them down
an internet connection. A third [3] sleeps its entire life away,
either making network requests and waiting for the responses, or
outright sleep()ing until it needs to go do something again. If the
cost of run-time lookups of dotted names were to increase by an order
of magnitude, not one of them would materially change in performance.
Sure, you can do microbenchmarks that show that Python takes X times
longer to parse "x.y.z" than Java does, but if that's seriously
impacting your real-world code, what are you doing?

About the only time when Python performance makes a real difference is
on startup. Mercurial, for instance, has to be invoked, initialized,
and shut down, for every command. (That's why git tends to outdo it in
a lot of ways, thanks to being written mainly in C and Perl.) So yes,
there are efforts every now and then to cut the startup time, where
however-many modules all have to get imported and set up. In the most
micro of microbenchmarks, here's what it takes to do nothing in
several languages:

rosuav at sikorsky:~$ cat
for i in {1..100}; do $@; done

rosuav at sikorsky:~$ time bash pike -e ';'

real 0m8.504s
user 0m7.928s
sys 0m0.436s
rosuav at sikorsky:~$ time bash python3 -c pass

real 0m3.094s
user 0m2.400s
sys 0m0.424s
rosuav at sikorsky:~$ time bash python2 -c pass

real 0m1.843s
user 0m1.136s
sys 0m0.488s

rosuav at sikorsky:~$ echo 'int main() {return 0;}' |gcc -x c -
rosuav at sikorsky:~$ time bash ./a.out

real 0m0.076s
user 0m0.004s
sys 0m0.012s

So, yeah. Pike's a poor choice and C's superb if you want to start up
and shut down real fast. Great. But as soon as those figures get
dwarfed by real work, nothing else matters. It's a rare situation
where you really need to start a program in less than 0.085 seconds.



More information about the Python-list mailing list