how fast is Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Epler

    #16
    Re: how fast is Python?

    I don't know what Mark Carter wanted to measure either, but I'd like to
    mention that when I compile "a.cpp" on my system with the flags Alex
    used, the generated code doesn't even include any floating-point
    arithmetic. The compiler was able to deduce that X was dead after the
    loop, and that its computation had no side-effects. I'm a little
    surprised that the compiler didn't completely remove the loop, but it's
    still there. "i" isn't there either, instead there's a counter that
    begins at 107, decrements and terminates the loop when it reaches -1.
    And if I use the directive to unroll loops, the logic is the same except
    that the counter decreases by 18 each time instead of 1.

    .... and anyway, this modified code (which does actually compute X when
    compiled on my system) aborts with a floating point overflow error.
    As far as I can tell, your program would be computing a value on the
    order of 10^(3x10^31)...

    Ah, the joy of writing the proverbial good benchmark.

    Jeff

    #include <fpu_control. h>
    fpu_control_t __fpu_control = _FPU_IEEE &~ _FPU_MASK_OM;

    double Y;

    int main()
    {
    double X = 0.5;
    for(int i = 0; i < 108; i++)
    X = 1 + X * X;
    Y = X;
    return 0;
    }


    Comment

    • Andrew Dalke

      #17
      Re: how fast is Python?

      Jeff Epler:[color=blue]
      > As far as I can tell, your program would be computing a value on the
      > order of 10^(3x10^31)...[/color]
      [color=blue]
      > for(int i = 0; i < 108; i++)
      > X = 1 + X * X;[/color]

      He had 1-X*X. Since X starts at 0.5, this will never go leave
      the range 0 to 1.

      Andrew
      dalke@dalkescie ntific.com


      Comment

      • Peter Hansen

        #18
        Re: how fast is Python?

        dan wrote:[color=blue]
        >
        > Peter Hansen <peter@engcorp. com> wrote in message news:<3F44DFEB. 60AB6492@engcor p.com>...
        > ...[color=green]
        > > And in those very few cases, so far, I have consistently concluded
        > > I'm happy enough with the speed of Python given that the speed of
        > > *development* in Python is easily 5 to 10 times faster than the
        > > speed of development in C. (And again, it's easy to find cases
        > > outside of this range, on either side...)
        > >[/color]
        > I pretty much agree. The point of my question was not to knock Python
        > -- I'm simply curious how fast, _in_principle_, a language like Python
        > could be made to run.
        >
        > I've looked at Psyco and Pyrex, I think both are interesting projects
        > but I doubt anything in the Py world has had nearly the kind of
        > man-hours devoted to optimization that Java, C++, and probably C# have
        > had.[/color]

        Oh, I completely misinterpreted the question then. I thought you wanted
        practical information.

        _In principle_, (which I'll interpret as "in theory"), Python can be made
        to run even faster than C or C++.

        In practice, nobody has been able to prove or disprove that theory yet...

        ;-)

        -Peter

        Comment

        • Christos TZOTZIOY Georgiou

          #19
          Re: how fast is Python?

          On 20 Aug 2003 13:08:20 -0700, rumours say that danbmil99@yahoo .com
          (dan) might have written:
          [color=blue]
          >How fast is Python, compared
          >to say a typical optimizing C/C++ compiler?[/color]

          The most important time for me is the time *I* invest in a program,
          since when it's run-time, I can always do other stuff while some slave
          computer follows my orders. So, I'll reply only about development time
          and I'll quote the Smiths: "How Soon Is Now?" :)
          --
          TZOTZIOY, I speak England very best,
          Microsoft Security Alert: the Matrix began as open source.

          Comment

          • Michele Simionato

            #20
            Re: how fast is Python?

            Alex Martelli <aleax@aleax.it > wrote in message news:<qJ%0b.116 361$cl3.3506646 @news2.tin.it>. ..[color=blue]
            > Irmen de Jong wrote:
            > ...[color=green]
            > > Nevertheless, a Psyco-optimized piece of Python code
            > > that runs as fast as compiled C is still very impressive
            > > to me. I know that JIT compiler technology theoretically
            > > could produce better optimized code than a static optimizing
            > > compiler, but am happy already if it reaches equal level :-)[/color]
            >
            > If anybody does have an actual example (idealy toy-sized:-)
            > where psyco's JIT does make repeatably faster code than a
            > C compiler (well-used, e.g. -O3 for gcc, NOT just -O...!-)
            > I'd be overjoyed to see it, by the way.
            >
            >
            > Alex[/color]

            Actually, as I posted in the C sharp thread of few weeks ago, on my
            machine psyco+psyco was FASTER than C. The numbers quoted are for C
            with
            option -o, but even for -o3 psyco was still faster and, notice, with
            pow(x,2) replacedby x*x in C too. I would be happy if somebody can
            reproduce that. Here is the link:



            Michele Simionato, Ph. D.
            MicheleSimionat o@libero.it

            --- Currently looking for a job ---

            Comment

            • Michele Simionato

              #21
              Re: how fast is Python?

              Alex Martelli <aleax@aleax.it > wrote in message news:<qJ%0b.116 361$cl3.3506646 @news2.tin.it>. ..[color=blue]
              > Irmen de Jong wrote:
              > ...[color=green]
              > > Nevertheless, a Psyco-optimized piece of Python code
              > > that runs as fast as compiled C is still very impressive
              > > to me. I know that JIT compiler technology theoretically
              > > could produce better optimized code than a static optimizing
              > > compiler, but am happy already if it reaches equal level :-)[/color]
              >
              > If anybody does have an actual example (idealy toy-sized:-)
              > where psyco's JIT does make repeatably faster code than a
              > C compiler (well-used, e.g. -O3 for gcc, NOT just -O...!-)
              > I'd be overjoyed to see it, by the way.
              >
              >
              > Alex[/color]

              Actually, as I posted in the C sharp thread of few weeks ago, on my
              machine psyco+psyco was FASTER than C. The numbers quoted are for C
              with
              option -o, but even for -o3 psyco was still faster and, notice, with
              pow(x,2) replacedby x*x in C too. I would be happy if somebody can
              reproduce that. Here is the link:



              Michele Simionato, Ph. D.
              MicheleSimionat o@libero.it

              --- Currently looking for a job ---

              Comment

              • Andrew Dalke

                #22
                Re: how fast is Python?

                Steven Taschuk:[color=blue]
                > A bit off-topic perhaps, but I'd be interested in the details of
                > [your] anecdote.[/color]

                Okay. I know someone who really likes optimized programming.
                The kind of person who will develop an in-memory compiler
                to generate specialized assembly for the exact parameters used,
                thus squeezing out a few extra cycles. He works in a C++ company.
                They used an idiom, the details of what I don't know. Most
                people wouldn't use that idiom because it didn't translate well
                to assembly, but the compiler in theory could figure it out. He
                submitted a patch to do that optimization. It was originally
                rejected because they couldn't see that anyone would write
                code that way. He dug around in gcc itself to find some place
                which used that code, to show that it is used. It was accepted.

                Moral: it's easier to change the technical details (gcc) than
                the social ones (getting people to use a better idiom).

                That's about all I know of the story.

                Andrew
                dalke@dalkescie ntific.com


                Comment

                • Graham Fawcett

                  #23
                  Counsel bears (OT, Re: how fast is Python?)

                  claird@lairds.c om (Cameron Laird) wrote in message news:<vkhl98pfv s6r34@corp.supe rnews.com>...[color=blue]
                  > In article <3F44DFEB.60AB6 492@engcorp.com >,
                  > Peter Hansen <peter@engcorp. com> wrote:[color=green]
                  > >dan wrote:[color=darkred]
                  > >>
                  > >> However, there are definitely cases where a lot of code would need to
                  > >> be optimized, and so I ask the question: How fast is Python, compared
                  > >> to say a typical optimizing C/C++ compiler?[/color]
                  > >
                  > >C is roughly 10 to 100 times faster than Python, though of course it's
                  > >easy to find cases outside of this range, on either side.
                  > >
                  > >I use 30 as a general overall rule of thumb, in the exceptionally
                  > >few cases where it seems relevant how much faster C would be.
                  > >
                  > >And in those very few cases, so far, I have consistently concluded
                  > >I'm happy enough with the speed of Python given that the speed of
                  > >*development * in Python is easily 5 to 10 times faster than the
                  > >speed of development in C. (And again, it's easy to find cases
                  > >outside of this range, on either side...)[/color]
                  > .
                  > .
                  > I just think Peter's wise counsel bears repeating.[/color]


                  My comment is completely off-topic, but I enjoyed a lyrical moment
                  when I mis-read Cameron's statement, and found myself imagining what
                  "Peter's wise counsel bears" looked like. I am envious of Peter,
                  having never made any magical forest-friends myself.

                  If we each had at least /one/ wise counsel bear, then c.l.py would
                  certainly reap the benefits of our enhanced posts!

                  Yours,

                  -- Graham

                  Comment

                  • Steve Horsley

                    #24
                    Re: how fast is Python?

                    On Wed, 20 Aug 2003 22:00:19 +0000, Andrew Dalke wrote:

                    [color=blue]
                    > Spend a few tens of millions on developing just-in-time compilers
                    > and program analysis. That worked for Java.[/color]

                    Have you heard of Jython - python language running on a java VM? It's kind
                    of double interpreted - the python source is converted to JVM bytecode,
                    and then the JVM runs it however that JVM runs bytecode. I guess it should
                    be many times faster than python because of the JVM performance, and
                    wopuld be interested to hear any comparisons.

                    Steve

                    Comment

                    • Lawrence Oluyede

                      #25
                      Re: how fast is Python?

                      "Steve Horsley" <steve.horsley1 @virgin.NO_SPAM .net> writes:
                      [color=blue]
                      > Have you heard of Jython - python language running on a java VM? It's kind
                      > of double interpreted - the python source is converted to JVM bytecode,
                      > and then the JVM runs it however that JVM runs bytecode. I guess it should
                      > be many times faster than python because of the JVM performance, and
                      > wopuld be interested to hear any comparisons.[/color]

                      Jython faster than Python? We did little test and it doesn't seem, look:
                      http://tinyurl.com/liix

                      --
                      Lawrence "Rhymes" Oluyede
                      Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

                      rhymes@NOSPAMmy self.com

                      Comment

                      • Robin Becker

                        #26
                        Re: how fast is Python?

                        In article <pan.2003.08.28 .19.40.59.80280 3@virgin.NO_SPA M.net>, Steve
                        Horsley <steve.horsley1 @virgin.NO_SPAM .net> writes[color=blue]
                        >On Wed, 20 Aug 2003 22:00:19 +0000, Andrew Dalke wrote:
                        >
                        >[color=green]
                        >> Spend a few tens of millions on developing just-in-time compilers
                        >> and program analysis. That worked for Java.[/color]
                        >
                        >Have you heard of Jython - python language running on a java VM? It's kind
                        >of double interpreted - the python source is converted to JVM bytecode,
                        >and then the JVM runs it however that JVM runs bytecode. I guess it should
                        >be many times faster than python because of the JVM performance, and
                        >wopuld be interested to hear any comparisons.
                        >
                        >Steve
                        >[/color]
                        experience with ReportLab suggests jython can be fairly slow compared to
                        CPython although it does have advantages.
                        --
                        Robin Becker

                        Comment

                        • Andrew MacIntyre

                          #27
                          Re: how fast is Python?

                          On Fri, 29 Aug 2003, Robin Becker wrote:
                          [color=blue]
                          > experience with ReportLab suggests jython can be fairly slow compared to
                          > CPython although it does have advantages.[/color]

                          The advantages being?

                          Regards,
                          Andrew.

                          --
                          Andrew I MacIntyre "These thoughts are mine alone..."
                          E-mail: andymac@bullsey e.apana.org.au (pref) | Snail: PO Box 370
                          andymac@pcug.or g.au (alt) | Belconnen ACT 2616
                          Web: http://www.andymac.org/ | Australia

                          Comment

                          • Alan Kennedy

                            #28
                            Re: how fast is Python?

                            [Steve Horsley][color=blue][color=green]
                            >> Have you heard of Jython - python language running on a java VM?
                            >> It's kind of double interpreted - the python source is converted
                            >> to JVM bytecode, and then the JVM runs it however that JVM runs
                            >> bytecode. I guess it should be many times faster than python
                            >> because of the JVM performance, and wopuld be interested to hear
                            >> any comparisons.[/color][/color]

                            [Lawrence Oluyede][color=blue]
                            > Jython faster than Python? We did little test and it doesn't seem, look:
                            > http://tinyurl.com/liix[/color]

                            Please bear in mind that the test code included the start up time for
                            interpreter. For jython, this is a high cost, because starting a JVM
                            often takes up to 10 seconds or more.

                            It would probably be fairer to run timings after the VM has already
                            been through the startup phase. I think that is a more valid
                            reflection of real-world scenarios where a VM gets started once and
                            left running for a long time.

                            regards,

                            --
                            alan kennedy
                            -----------------------------------------------------
                            check http headers here: http://xhaus.com/headers
                            email alan: http://xhaus.com/mailto/alan

                            Comment

                            • Lawrence Oluyede

                              #29
                              Re: how fast is Python?

                              Andrew MacIntyre <andymac@bullse ye.apana.org.au > writes:
                              [color=blue]
                              > The advantages being?[/color]

                              I think gain access to Java stuff is an advantage in some situations,
                              isn't it?

                              --
                              Lawrence "Rhymes" Oluyede
                              Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

                              rhymes@NOSPAMmy self.com

                              Comment

                              • Lawrence Oluyede

                                #30
                                Re: how fast is Python?

                                Alan Kennedy <alanmk@hotmail .com> writes:
                                [color=blue]
                                > Please bear in mind that the test code included the start up time for
                                > interpreter. For jython, this is a high cost, because starting a JVM
                                > often takes up to 10 seconds or more.[/color]

                                Yeah, you right. But here comes a question: why do you think that Jython
                                (and JVM) are faster than Python (and its VM)? In my own little tests is
                                Jython is always slower and GUI (with Swing) is not responsive as GTK for
                                example. I think Jython is an amazing and awesome "tool" for Python and
                                Java developers but I'm not so sure that is also faster than CPython.

                                Bye!


                                --
                                Lawrence "Rhymes" Oluyede
                                Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

                                rhymes@NOSPAMmy self.com

                                Comment

                                Working...