why python is slower than java?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cameron Laird

    #16
    Re: why python is slower than java?

    In article <pan.2004.11.05 .09.23.39.24871 8@yahoo.com>,
    John Doe <atterdan@yahoo .com> wrote:

    Comment

    • Mike Meyer

      #17
      Re: why python is slower than java?

      finite.automato n@gmail.com (Lonnie Princehouse) writes:
      [color=blue]
      > Yes, wxPython is typically quicker than swing. It's not fair to use
      > this in a generic Python-vs-Java speed shootout, though, since
      > wxPython is just a wrapper around wxWidgets' C++ code; you're really
      > comparing C++ vs. Java here.[/color]

      Is it unfair to compare Python dictionaries to Java HashTables because
      Python is using hand-tuned C where Java is using Java? I'd say that's
      a perfectly fair comparison. If that's fair, what's unfair about
      comparing graphics toolkits that happen to be written in C rather than
      Python (is there a graphics toolkit written in Python?).

      That's *how* interpreted languages manage to compete with compiled
      languages - they perform the common operations in hand-tuned compiled
      code. That people tend to write Java libraries in Java rather than C
      just means they're going to get slower libraries.
      [color=blue]
      > AFAIK the major two reasons for Python's relative slowness are that
      > it's interpreted and dynamically typed.[/color]

      Java is interpreted just like Python is. The only difference is that
      Java splits the compiler and VM implementation into two different
      binaries.

      <mike
      --
      Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
      Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

      Comment

      • Steve Menard

        #18
        Re: why python is slower than java?

        Mike Meyer wrote:[color=blue]
        > finite.automato n@gmail.com (Lonnie Princehouse) writes:
        >
        >[color=green]
        >>Yes, wxPython is typically quicker than swing. It's not fair to use
        >>this in a generic Python-vs-Java speed shootout, though, since
        >>wxPython is just a wrapper around wxWidgets' C++ code; you're really
        >>comparing C++ vs. Java here.[/color]
        >
        >
        > Is it unfair to compare Python dictionaries to Java HashTables because
        > Python is using hand-tuned C where Java is using Java? I'd say that's
        > a perfectly fair comparison. If that's fair, what's unfair about
        > comparing graphics toolkits that happen to be written in C rather than
        > Python (is there a graphics toolkit written in Python?).
        >
        > That's *how* interpreted languages manage to compete with compiled
        > languages - they perform the common operations in hand-tuned compiled
        > code. That people tend to write Java libraries in Java rather than C
        > just means they're going to get slower libraries.
        >
        >[color=green]
        >>AFAIK the major two reasons for Python's relative slowness are that
        >>it's interpreted and dynamically typed.[/color]
        >
        >
        > Java is interpreted just like Python is. The only difference is that
        > Java splits the compiler and VM implementation into two different
        > binaries.
        >
        > <mike[/color]

        Actually java has not been interpreted for quite a few years. Java today
        is compiled to native code at runtime (JIT), exactly like what Psyco
        tries to do for Python. This means the only things that (today) makes a
        java program slower than a C program are Java's added safety features (
        Bounds-checking on arrays and garbage collection to name but two).

        Java's speed and Python's speed are not absolute values. Java IS faster
        than python when it comes to CPU-intensive operations. IF you given
        problem is heavily IO-bound, then python will be just as fast as Java.
        Also, if you are writing a GUI application, your program will spend most
        of its time waiting for user-input and not much difference will be
        noticed. Python may even win out in that case since it's GUI are
        typically platform-tuned C/C++ libraries wrapped in Python.


        Steve

        Comment

        • Alex Martelli

          #19
          Re: why python is slower than java?

          Hans Nowak <hans@zephyrfal con.org> wrote:
          [color=blue]
          > John Machin wrote:
          >[color=green]
          > > Or is this a joke/troll?? I can't believe the "unimelb.edu.au "; surely
          > > a forgery.[/color]
          >
          > Is it just me, or is the climate in c.l.py getting less friendly to
          > newbies? In any case,[/color]

          Interestingly enough, I sort of share your perception -- and I have
          noticed the same thing, and seen it remarked upon by others, in other,
          completely unrelated newsgroups as well, such as it.comp.macinto sh.

          It's not, I think, about newbies in general: people who come and post
          help requests, without giving the information that's quite obviously
          indispensabile to let us help them, keep getting treated with
          unreasonable amounts of friendliness and courtesy even after many
          requests for more info go unheeded, for example.

          However, newbies who are clueless enough to come blasting in with the
          usual whines we've heard a zillion times -- Macs cost too much, Python
          is too slow, there's no apps for Macs, Python must absolutely add
          feature X or it will die, Apple's gonna go broke tomorrow, etc, etc --
          do appear to get on our collective nerves worse than their essentially
          indistinguishab le precursors did last year, two years ago, &c.

          The accusation of being a troll often follows, breaking the old advice
          to "Never attribute to malice what can be adequately explained by
          incompetence". Maybe it's a case of the corollary to that old advice,
          "Sufficient ly advanced cluelessness is indistinguishab le from malice".
          But why that should be so this year more than last year, say, is not
          clear to me...


          Alex

          Comment

          • Maurice LING

            #20
            Re: why python is slower than java?

            [color=blue]
            > Interestingly enough, I sort of share your perception -- and I have
            > noticed the same thing, and seen it remarked upon by others, in other,
            > completely unrelated newsgroups as well, such as it.comp.macinto sh.
            >
            > It's not, I think, about newbies in general: people who come and post
            > help requests, without giving the information that's quite obviously
            > indispensabile to let us help them, keep getting treated with
            > unreasonable amounts of friendliness and courtesy even after many
            > requests for more info go unheeded, for example.
            >
            > However, newbies who are clueless enough to come blasting in with the
            > usual whines we've heard a zillion times -- Macs cost too much, Python
            > is too slow, there's no apps for Macs, Python must absolutely add
            > feature X or it will die, Apple's gonna go broke tomorrow, etc, etc --
            > do appear to get on our collective nerves worse than their essentially
            > indistinguishab le precursors did last year, two years ago, &c.
            >
            > The accusation of being a troll often follows, breaking the old advice
            > to "Never attribute to malice what can be adequately explained by
            > incompetence". Maybe it's a case of the corollary to that old advice,
            > "Sufficient ly advanced cluelessness is indistinguishab le from malice".
            > But why that should be so this year more than last year, say, is not
            > clear to me...
            >
            >
            > Alex[/color]

            I've already said the following and was not noticed:

            1. it is a disk intensive I/O operation.
            2. users delay is not in the equation (there is no user input)
            3. I am not interested in the amount of time needed to develop it. But
            only interested execution speed.

            Thanks maurice

            Comment

            • Maurice LING

              #21
              Re: why python is slower than java?

              [color=blue]
              > In this way version 1.0 is all python. v1.1 has 20% C++; v1.2 is 34% C++
              > ... until v2.0 is all C++. Each upgrades is faster, but does not introduce
              > any new functionality and the risks that new functions imply.
              >
              > If you were faithful to this concept, version 3 requires you to use the
              > oldest python branch who's functions will not be modified, to start
              > development. Could be v1.1 or 1.9.
              >[/color]
              I don't quite get the last part right, the version 3 part. I got lost in
              it....

              thanks maurice

              Comment

              • Maurice LING

                #22
                Re: why python is slower than java?

                [color=blue]
                >
                > Do you have any data to support this ?
                > On Windows XP, Windows NT and Linux (Gentoo ), I have consistently
                > found python apps using wxpython to be far faster to load
                > and to be far more responsive than Java apps.[/color]

                well, I do not have data to support this. Just based on an impression,
                perhaps seriously flawed impression. maurice

                Comment

                • Harald Massa

                  #23
                  Re: why python is slower than java?

                  Israel Raj T <rambam@bigpond .net.au> wrote in news:878y9gbkh7 .fsf@pop-
                  server.bigpond. net.au:
                  [color=blue]
                  > On the updated version at http://shootout.alioth.debian.org/craps.php,
                  > Python beats at least two java implementations .[/color]

                  Very interesting link, great ressource!!!

                  What really is disturbing: within the test "hash access" perl2 comes out
                  first compared with java.

                  A know that Python dictionaries are the most heavily used datastructure
                  (because it is allways used within Python itself), and from looking at the
                  sourcecode there is the line "with help from Raymund Hettinger"; so I am
                  very sure it is probably THE optimal coding.

                  So... string processing, regular expression, blablabla no problem; but why
                  second to perl2 in Hash-access ???

                  Harald

                  Comment

                  • gabriele renzi

                    #24
                    Re: why python is slower than java?

                    Harald Massa ha scritto:[color=blue]
                    > Israel Raj T <rambam@bigpond .net.au> wrote in news:878y9gbkh7 .fsf@pop-
                    > server.bigpond. net.au:
                    >
                    >[color=green]
                    >>On the updated version at http://shootout.alioth.debian.org/craps.php,
                    >>Python beats at least two java implementations .[/color]
                    >
                    >
                    > Very interesting link, great ressource!!!
                    >
                    > What really is disturbing: within the test "hash access" perl2 comes out
                    > first compared with java.
                    >
                    > A know that Python dictionaries are the most heavily used datastructure
                    > (because it is allways used within Python itself), and from looking at the
                    > sourcecode there is the line "with help from Raymund Hettinger"; so I am
                    > very sure it is probably THE optimal coding.
                    >
                    > So... string processing, regular expression, blablabla no problem; but why
                    > second to perl2 in Hash-access ???[/color]

                    maybe because perl has been polished for more years :)
                    Anyway, 3 things worth noting about the shootou

                    - you won't *ever* write heapsort and things like that in python,
                    obviously it is slow, and obviously you have'em builtin.
                    - there are some tricks like using numarray for matrix calculations
                    - the ranking system is named CRAP(s).

                    Comment

                    • Alex Martelli

                      #25
                      Re: why python is slower than java?


                      On 2004 Nov 06, at 08:31, Maurice LING wrote:
                      ...[color=blue]
                      > 1. it is a disk intensive I/O operation.
                      > 2. users delay is not in the equation (there is no user input)
                      > 3. I am not interested in the amount of time needed to develop it. But
                      > only interested execution speed.[/color]

                      OK, could you provide a simple toy example that meets these conditions
                      -- does lot of identical disk-intensive I/O "in batch" -- and the
                      execution speed measured (and on what platform) for what Python and
                      Java implementations , please?

                      For example, taking a trivial Copy.java from somewhere on the net:

                      import java.io.*;

                      public class Copy {
                      public static void main(String[] args) throws IOException {
                      File inputFile = new File("/usr/share/dict/web2");
                      File outputFile = new File("/tmp/acopy");

                      FileReader in = new FileReader(inpu tFile);
                      FileWriter out = new FileWriter(outp utFile);
                      int c;

                      while ((c = in.read()) != -1)
                      out.write(c);

                      in.close();
                      out.close();
                      }
                      }

                      and I observe (on an iBook 800, MacOSX 10.3.5):

                      kallisti:~ alex$ java -version
                      java version "1.4.2_05"
                      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-141.3)
                      Java HotSpot(TM) Client VM (build 1.4.2-38, mixed mode)

                      -r--r--r-- 1 root wheel 2486825 12 Sep 2003 /usr/share/dict/web2

                      kallisti:~ alex$ time java Copy

                      real 0m7.058s
                      user 0m5.820s
                      sys 0m0.390s

                      versus:

                      kallisti:~ alex$ time python2.4 Copy.py

                      real 0m0.296s
                      user 0m0.080s
                      sys 0m0.170s

                      with Python 2.4 beta 1 for the roughly equivalent:

                      inputFile = file("/usr/share/dict/web2", 'r')
                      outputFile = file("/tmp/acopy", 'w')

                      outputFile.writ e(inputFile.rea d())

                      inputFile.close ()
                      outputFile.clos e()

                      which isn't all that far from highly optimized system commands:

                      kallisti:~ alex$ time cp /usr/share/dict/web2 /tmp/acopy

                      real 0m0.167s
                      user 0m0.000s
                      sys 0m0.040s

                      kallisti:~ alex$ time cat /usr/share/dict/web2 >/tmp/acopy

                      real 0m0.149s
                      user 0m0.000s
                      sys 0m0.090s


                      I'm sure the Java version can be optimized easily, too -- I just
                      grabbed the first thing I saw off the net. But surely this example
                      doesn't point to any big performance issue with Python disk I/O wrt
                      Java. So, unless you post concrete examples yourself, the smallest the
                      better, it's going to be pretty difficult to understand where your
                      doubts are coming from!


                      Alex

                      Comment

                      • Carlos Ribeiro

                        #26
                        Re: why python is slower than java?

                        On Fri, 05 Nov 2004 18:33:10 -0500, Hans Nowak <hans@zephyrfal con.org> wrote:[color=blue]
                        > John Machin wrote:
                        >[color=green]
                        > > Or is this a joke/troll?? I can't believe the "unimelb.edu.au "; surely
                        > > a forgery.[/color]
                        >
                        > Is it just me, or is the climate in c.l.py getting less friendly to
                        > newbies? In any case,
                        > http://www.zoology.unimelb.edu.au/staff/nicholas.htm mentions Maurice
                        > Ling as an honor student.[/color]

                        Not only that, but Maurice Ling has started a long thread a few weeks
                        looking for a good research topic for his thesis (involving Java &
                        Python, btw). At some points he was bashed, but went ahead with the
                        discussion, that ended up touching in several interesting topics.

                        As for the climate in c.l.py, it's just interesting to note that the
                        climate *is* getting less friendly, and that it does coincide with
                        several old-timers moving away from the list. A few years ago I
                        remember that the likes of Tim Peters, effbot, Skip Montanaro, and
                        several others (sorry, I would really like to remember more names from
                        the top of my head) were frequent posters here. They've now moved to
                        other interests, or are focusing their efforts on the python-dev list.
                        It must not be a coincidence.

                        --
                        Carlos Ribeiro
                        Consultoria em Projetos
                        blog: http://rascunhosrotos.blogspot.com
                        blog: http://pythonnotes.blogspot.com
                        mail: carribeiro@gmai l.com
                        mail: carribeiro@yaho o.com

                        Comment

                        • Carlos Ribeiro

                          #27
                          Re: why python is slower than java?

                          On Sat, 6 Nov 2004 08:12:10 +0100, Alex Martelli <aleaxit@yahoo. com> wrote:[color=blue]
                          > "Sufficient ly advanced cluelessness is indistinguishab le from malice".[/color]

                          Although not originally yours, anyway: +100 QOTW!
                          [color=blue]
                          > But why that should be so this year more than last year, say, is not
                          > clear to me...[/color]

                          I think that (at least for c.l.py) it has something to do with the
                          fact that several old-timers are moving away from the list. I don't
                          know if this is a cause or a consequence. But it's not a coincidence,
                          IMHO.

                          --
                          Carlos Ribeiro
                          Consultoria em Projetos
                          blog: http://rascunhosrotos.blogspot.com
                          blog: http://pythonnotes.blogspot.com
                          mail: carribeiro@gmai l.com
                          mail: carribeiro@yaho o.com

                          Comment

                          • Eric S. Johansson

                            #28
                            Re: why python is slower than java?

                            Alex Martelli wrote:[color=blue]
                            > Hans Nowak <hans@zephyrfal con.org> wrote:
                            >
                            >[color=green]
                            >>John Machin wrote:
                            >>
                            >>[color=darkred]
                            >>>Or is this a joke/troll?? I can't believe the "unimelb.edu.au "; surely
                            >>>a forgery.[/color]
                            >>
                            >>Is it just me, or is the climate in c.l.py getting less friendly to
                            >>newbies? In any case,[/color]
                            >
                            >
                            > Interestingly enough, I sort of share your perception -- and I have
                            > noticed the same thing, and seen it remarked upon by others, in other,
                            > completely unrelated newsgroups as well, such as it.comp.macinto sh.[/color]

                            I think it can be explained by donor fatigue.

                            I've experienced this on a couple of projects where the initial
                            developers/intellectual foundation are very helpful and a lot of work
                            and they get burned out. The Next Generation comes along and doesn't
                            quite know enough to be able to handout ready answers but tries real
                            hard and get frustrated. Users get frustrated and then as you point
                            out, the clueless twits start dominating the conversation. Sort of an
                            intellectual approximation of Gresham's law.

                            I know from my perspective, I have been reluctant to really talk much
                            about what I've done with Python in developing the camram anti-spam
                            system because of fatigue of a different type. It is a radically
                            different system and the very odd thing is that ordinary users get it in
                            a heartbeat and many technologists fight it with every fiber of their being.

                            so as a result, I ask questions trying to describe the abstract case of
                            what I'm trying to do so that I don't get distracted down a rathole of
                            defending the application. Needless to say, I suspect others are doing
                            the same thing and it's really really hard to describe the abstract case
                            in a way that's clear.

                            now I'm going to throw out another radical idea for dealing with donor
                            fatigue: I will argue that we might want to start including in the
                            headers of mailing list/newsgroups a dana reference. If you are
                            familiar with Buddhist culture, dana is an expression of generosity. A
                            gift given in response to a priceless lesson. There is no expectation
                            giving and there is no expectation of receiving.
                            http://www.accesstoinsight.org/ptf/dana.html therefore, with a dana
                            header, someone who is happy with the answer to a question could gift
                            some money to the recipient.

                            I'll argue that some form of compensation system is necessary to help
                            combat donor fatigue. We all live for reward stimuli be it money, sex,
                            chocolate. Compulsory "pay for the answer" systems don't work well
                            because you have no assurance that you'll get an answer you can use.
                            The flip side "pay for the cheapest answer that meets your needs" does
                            not encourage participation because it's usually a financial race to the
                            bottom. I think the middle path of Dana is the most likely to succeed
                            although it won't make anybody rich. You contribute and maybe somebody
                            will thank you for it. You'll know that it was given in the spirit of
                            generosity and kindness, not because of a contractual requirement.

                            another advantage of this idea is that it builds on the existing
                            infrastructure of mailing lists and newsgroups not a walled garden of a
                            web site somewhere.

                            There are some challenges connecting the dana id to financial systems
                            and e-mail/news clients. But these are known problems with solutions
                            and with tools like Thunderbird, we can easily make modifications and
                            make them available.

                            ---eric

                            Comment

                            • Kendall Clark

                              #29
                              Re: why python is slower than java?

                              On Fri, Nov 05, 2004 at 05:58:09AM +0000, Maurice LING wrote:[color=blue]
                              > This may be a dumb thing to ask, but besides the penalty for dynamic
                              > typing, is there any other real reasons that Python is slower than Java?[/color]

                              I favor a different kind of explanation than the ones usually offered
                              here. While the degree to which Python is "slower than Java" will
                              depend in large part on what you're trying to do with both of them,
                              it's also the case that Java leads Python by probably $1 billion
                              dollars, if not more, in JIT compiler R&D.

                              The main reason Java is "faster" is because it's been backed by Sun
                              and IBM, for use in enterprise applications, on some of the biggest
                              hardware available, and they've put massive R&D effort (i.e., money)
                              into making it faster.

                              I suspect if MS had chosen Python instead of C#, and then spent a few
                              billion and 5 to 10 years of R&D effort, people would be asking why
                              Perl is so much slower than Python.

                              Common Lisp is fast because it's had similar R&D effort, spread out
                              over 40 years or so, going back to the first Lisps. Same goes for
                              Smalltalk. Java is fast because Sun & IBM and others decided it had to
                              be. Python is slower because the Python community is incomparably
                              smaller, less well-heeled, and mostly doesn't care too much about
                              performance.

                              There are *technical* reasons for all of this, but I think those
                              reasons exist largely because of non-technical, social reasons.

                              My two cents. :>

                              Best,
                              Kendall Clark
                              --
                              Sometimes it's appropriate, even patriotic, to be ashamed
                              of your country. -- James Howard Kunstler

                              Comment

                              • Dan Perl

                                #30
                                Re: why python is slower than java?


                                "Alex Martelli" <aleaxit@yahoo. com> wrote in message
                                news:1gmtkpc.1h 26kkr1rd529sN%a leaxit@yahoo.co m...[color=blue]
                                > Hans Nowak <hans@zephyrfal con.org> wrote:
                                >[color=green]
                                >> John Machin wrote:
                                >>[color=darkred]
                                >> > Or is this a joke/troll?? I can't believe the "unimelb.edu.au "; surely
                                >> > a forgery.[/color]
                                >>
                                >> Is it just me, or is the climate in c.l.py getting less friendly to
                                >> newbies? In any case,[/color]
                                >
                                > Interestingly enough, I sort of share your perception -- and I have
                                > noticed the same thing, and seen it remarked upon by others, in other,
                                > completely unrelated newsgroups as well, such as it.comp.macinto sh.[/color]

                                I'm still one of the newbies and I was not reading this newsgroup a year
                                ago, so I cannot draw any comparisons, but I wonder, has this group also
                                grown much during this time? Could this be a cultural thing like the
                                difference between a small town culture and a big city culture?
                                [color=blue]
                                > It's not, I think, about newbies in general: people who come and post
                                > help requests, without giving the information that's quite obviously
                                > indispensabile to let us help them, keep getting treated with
                                > unreasonable amounts of friendliness and courtesy even after many
                                > requests for more info go unheeded, for example.
                                >
                                > However, newbies who are clueless enough to come blasting in with the
                                > usual whines we've heard a zillion times -- Macs cost too much, Python
                                > is too slow, there's no apps for Macs, Python must absolutely add
                                > feature X or it will die, Apple's gonna go broke tomorrow, etc, etc --
                                > do appear to get on our collective nerves worse than their essentially
                                > indistinguishab le precursors did last year, two years ago, &c.[/color]

                                I have complained myself about several aspects of Python that I was
                                discovering as I was learning it (although I never said Python will die).
                                But I have been programming for enough years to believe that I am entitled
                                to have an opinion even in something that I am new at and that I am entitled
                                to express that opinion.

                                On the other hand, as I become more experienced in Python and I have
                                opportunities to help other people who are even newer at this than I am, I
                                also feel some frustration when I do not get enough help from them to help
                                them. But I probably can still relate better to them because, like them, I
                                still need help in so many areas.

                                IMO, we all must show more tolerance. I believe though that newbies are
                                naturally more tolerant of experts because newbies need the experts. So I
                                am making a plea particularly to experts to show more tolerance to newbies.
                                The newbies' complaints come out of frustration, frustration just like
                                yours, which shows in terms like "clueless", "blasting in", and "whines
                                we've heard a zillion times", all in just one sentence (and that is in a
                                discussion on friendliness towards newbies).

                                Are you learning any new subject now and are you involved in a newsgroup as
                                a newbie? If you're not doing that already, python experts, please try it
                                and you'll probably see what it's like. No better way to see the other
                                side's point of view than being on the other side.

                                Dan


                                Comment

                                Working...