Why is this question so beloved? Re: Is python really slow?

David LeBlanc whisper at oz.net
Wed May 22 20:19:04 EDT 2002


Chris;

Sorry, I had meant this to start a new thread. No attempt to redicule your
query was intended. If by now you've decided to use Python, that's great. If
not, here are a few reasons to select it in comparison with Perl and C.

Syntax: Python and C have a cleaner syntax then Perl. This leads to better
maintenence, updates/enhancements and reuse of code. That, over the term of
an application is one kind of performance advantage.

Modularity: Both Perl and Python have (IMO) cleaner modularization features
with perl modules and Python packages compared to C's comparative lack of
any such feature. I think Python gets a plus here with sub-packages, but I
don't know that Perl doesn't also offer that. Performance advantage is that
modularization supports easy construction and maintenence of larger
applications.

Ease: Of the three, Python is by far the easiest to use. Perl has an
interactive mode of sorts, but i've never seen or heard of it being used or
promoted much. With C you get the whole
edit/compile/debug/edit/compile/debug... cycle. With Python you can code a
little, debug a little, code a litte... Python's interactive console mode
facilitates writing quick snippets of code to check out how something works
or to confirm an idea. Performance gain is rapidity of prototyping.

Friendliness: C bites (and it's been biting me for... 20ish years now :) ).
C's basic syntax isn't hard, but some of the semantics are troublesome for
beginners and that makes the learning curve steeper. C's use of pointers is
probably the best example of this type of issue. Perl has the problem that
there are so many ways to do things and some of those things treat variables
differently depending on something as minor as using @ vs. # (or was it
$...). Python generally has one simple way to do most anything you want to
do. Building upon tested code is a perfomance gain in development.

Conciseness: Yes, it's true, you can write a perl program that looks like a
keyboard spewed every punctuation character and combinations thereof and it
will do wizardly things - and you'll puzzle out how to rewrite it every time
you walk away from it for more then a week when it needs fixing or
modification. Python is less concise in this regard then Perl, but far more
consise then C. It's big gain over C is the availabilty of more intrinsic
datatypes and means of slicing and dicing those datatyes. (An associate
claims he turned 4,000 lines of Java into 400 lines of Python code that did
the same thing.) Performance advantage is writing less code to get more
done.

Speed: C is the odds on winner here, as would any compiled language. When
comparing any byte code interpreted language (Java, Tcl, Perl, Python), it
is possible to write a benchmark that underscores the performance advantage
of particular features of a language and that's where the red faces and hand
waving starts. Benchmarks also tend to be artificial and don't reflect
reality well. Raw speed - "bytecodes per second" - is probably the least
useful of metrics when evaluating the overall performance of a language.
Having said that, in all the Python vs. <other favored language(s) here>,
Python's numbers clump pretty closely with other like-implemented languages,
including Tcl (bytecoded versions), Perl and Java.

Extensibility: Whatever "scripting language" you use, at some point you're
going to encounter that 2% of your code that just isn't fast enough in that
language and you're either going to have to abandon that language in favor
of a compiled language (such as C) or write an extension for your
interpreted language to do the part that has to be fast. One of the design
goals for Perl 6 is to make extending Perl easier - reportedly it's
challenging to do with Perl 5 and below. Python makes a point of being both
extensible (and embeddable) and provides a well documented API for writing
extensions. In C _everything_ is an extension :-). All three languages offer
an extensive array of 3rd party libraries/packages/modules which include
compiled extensions for performance enhancement, so chances are you're never
going to have to write an extension anyway unless you're doing something
very esoteric and/or proprietary. The advantage here is that you can write
most of your code in Python with all of the above performance advantages and
still have a reasonably easy time of extending it if you ever have to.

There are too many other good things about Python to go into them in detail,
however one is worth mentioning: neither Perl nor C have intrinsic support
for object oriented programming (in Perl, it's a language extension with
many flaws, not built-in). I think the performance advantages of OO are well
known (and subject to debate: no flames thankyouverymuch), so i'm not going
to mention them.

Performance is a lot of factors.

HTH,

Dave LeBlanc
Seattle, WA USA






More information about the Python-list mailing list