why python is slower than java?

Alex Martelli aleaxit at yahoo.com
Sat Nov 6 16:25:58 EST 2004


Roger Binns <rogerb at rogerbinns.com> wrote:

> Alex Martelli wrote:
> >         while ((c = in.read()) != -1)
> >            out.write(c);
> 
> Incidentally, that Java code copies one character at a time.

Yep, I noticed -- pretty silly, but if that's how the Java designers
decided the read method should behave by default, who am I to argue?
Just an example I grabbed off the net, first google hit for (if I recall
correctly) java file reading that had the source of a complete example.

> > outputFile.write(inputFile.read())
> 
> The Python code is reading the entire string into memory and
> then writing it.

Right, _Python_'s default.

> The interpretter overhead vs system calls could be measured
> by having the language involved in every byte transferred as
> in the Java example, or negligibly as in the Python example.

The claim posted to this newsgroup, without any support nor examples
being given, was that Python's I/O was far slower than Java's in
_disk-intensive_ operations.  I'm still waiting to see any small,
verifiable examples of that posted on this thead.

Apparently, at least in default operations on both sides, based on calls
to read without parameters, that is definitely not the case - no doubt,
as you say, that's because of the different ways those defaults are
tuned, making Python much faster.  Great, then let those who claim
Java's I/O is much faster in disk intensive operation post suitable
examples, and we'll see.


> Whenever anyone has an agenda, you can make all sorts of silly
> claims.  IMHO the best thing to do is to lead by examples.

I posted examples -- probably not "leading" ones, just one grabbed off
the net using Java's defaults, and one using Python's defaults.  I'm not
the one making any claims regarding I/O performance of _properly tuned_
disk-intensive programs -- what I would like to see would be some such
examples posted by those who DO make such claims.  Shouldn't the burden
of proof lay on the side making positive assertions, by ordinary rules?!

> For years many people claimed Perl was line noise, hard to
> maintain etc.  I never really saw much response, since the
> Perl people were too busy writing real world code and helping
> deliver part of the web revolution.  (And selling zillions of
> books for O'Reilly :-)

Surely more than we have sold so far with Python, yes - Tim O'Reilly has
published data about that.  Which is why I'm striving to _worsen_ the
quality of Python's free docs until they match Perl's, against heathens
who (can you imagine that!) are instead trying to *improve* them further
(thus no doubt hurting book sales).


> I couldn't find any Python success stories on python.org itself,
> but if you dig you can find the stories for the Python Business
> Forum as well as Pythonology.

Lots of digging, yes, considering that if you google for python success
stories those pbf and pythonology hits are just at the top (other
similar links, such as those to O'Reilly's booklets covering the same
material and their PDF forms, make up the rest of the top-ten pages).

> There are however remarkably few where you can go grab the
> source code and see how it is all put together.  In fact I
> couldn't find a single one, but didn't do an exhaustive
> search from python.org.

Without straying from the top google hit, you can find that some of the
listed success stories are open-source, such as mayavi -- they're
admittedly a minority of the "success stories" listed on these sites.

> Perhaps it is also worth linking to the projects done in
> Python on SourceForge and elsewhere?
> 
>   http://sf.net/softwaremap/trove_list.php?form_cat=178

If the message you're keen to send is "Python is great for open-source",
yes.  If you're focusing on "Python is great for your _business_" (as
the python *business* forum does, for example), then emphasizing
open-source projects can reasonably be considered secondary to
emphasizing projects that make or save money for the businesses which
developed them.

If you're looking for highly visible open-source projects using Python,
I'd think that bittorrent, chandler, zope and plone, mayavi, all the
scipy.org site, twisted, schooltool, ubuntu, and the like, should keep
you in reading materials for a while.  Not sure how many of these
projects are specifically on sourceforge, but I believe some minority
probably is.


Alex



More information about the Python-list mailing list