Is python very slow compared to C

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • diffuser78@gmail.com

    Is python very slow compared to C

    I have just started to learn python. Some said that its slow. Can
    somebody pin point the issue.

    Thans

  • rtilley

    #2
    Re: Is python very slow compared to C

    diffuser78@gmai l.com wrote:[color=blue]
    > I have just started to learn python. Some said that its slow. Can
    > somebody pin point the issue.[/color]

    It depends on what you are doing. Much of Python is just wrapped C. So
    many things are very fast.

    Comment

    • Robert Hicks

      #3
      Re: Is python very slow compared to C

      Most languages are slow compared to "C". Python is fast enough for just
      about anything you want to do with it.

      Robert

      Comment

      • bearophileHUGS@lycos.com

        #4
        Re: Is python very slow compared to C

        Yes this language is very slow, but frequently this isn't a problem,
        because you are using fast functions/libraries written in C, or you are
        doing I/O bound operations. And Psyco, numeric/numarray, ShedSkin can
        help in some other cases (Pyrex and other solutions allow you to mix in
        lower level languages). If you are looking for pure algorithmic speed
        you probably have to go look for other languages, like C, C++, Ocaml,
        typed Lisp code, etc.

        Bye,
        bearophile

        Comment

        • Larry Bates

          #5
          Re: Is python very slow compared to C

          diffuser78@gmai l.com wrote:[color=blue]
          > I have just started to learn python. Some said that its slow. Can
          > somebody pin point the issue.
          >
          > Thans
          >[/color]
          "Some" doesn't know what he/she/they are talking about.
          Generalizations like that upset me because it shows someone
          that has some predisposition to some other language and they
          don't want to be confused by "facts". Many "compiled
          language" programmers fall into this category. Many times
          you can write, debug, execute, and document a Python program
          before "compiled language" guys can even get started. Many
          believe that Python is also more maintainable over time.
          When you come back to it in 6 months you will ACTUALLY BE ABLE
          TO READ THE CODE. Productivity cannot be measured by
          benchmarks alone.

          Give Python a try and I'll bet you find that it is fast enough
          (that's all that is important right) for all but device
          drivers and highly scientific applications (and even then
          there are solutions). The parts of Python that need to be
          fast have been rewritten as binary libraries. That way you
          get the best of both worlds: high level language that has
          fast libraries when required.

          -Larry Bates

          Comment

          • Michael Tobis

            #6
            Re: Is python very slow compared to C

            Experienced programmers learning Python should read this:



            Try to understand the advantages of this approach, and understand its
            costs.

            Essentially, everything you do in Python (or related languages)
            involves resolving a name. Sometimes the number of dictionary look-ups
            (name dereferences) required to do anything is very expensive in
            runtime performance.

            If your code is not compute-bound (as most codes are not; these days
            communication-bound or limited by database performance are more common)
            the increase in your own performance will be much more important. If
            your code does do so much computing (as mine do) that performance
            matters, you may still find Python useful, but it is less of a
            slam-dunk.

            mt

            Comment

            • Steven D'Aprano

              #7
              Re: Is python very slow compared to C

              On Sat, 11 Feb 2006 12:49:32 -0800, diffuser78 wrote:
              [color=blue]
              > I have just started to learn python. Some said that its slow.[/color]

              No, you can learn the basics of Python is only a few hours, and become
              very proficient at it in days or weeks. It is much faster to learn Python
              than to learn C.
              [color=blue]
              > Can somebody pin point the issue.[/color]

              What is slow? Slow compared to what? Would you prefer to spend three days
              writing a program that will run in twenty milliseconds, or three hours
              writing the same program which runs in eighty milliseconds? Is the
              computer's execution time more important than your development time? If
              the computer's time is more valuable than your time, then you should be
              writing in assembly language.

              Python helps you write shorter code with fewer bugs, much quicker, than C.
              If you discover a specific problem that runs too slow in Python, it is
              possible to write a C extension to solve that specific problem, while
              still having all the other advantages of Python.


              --
              Steven.

              Comment

              • Steven D'Aprano

                #8
                Re: Is python very slow compared to C

                On Sat, 11 Feb 2006 13:52:03 -0800, bearophileHUGS wrote:
                [color=blue]
                > Yes this language is very slow,[/color]

                Very slow to do what, compared to what? The decay time of the tau meson?

                Slowness is not an absolute quantity. Slowness is relative, and comments
                like "Python is very slow" just reinforces the meme that execution speed
                is the only important factor -- even if you follow up with a good (and
                correct) description of why raw CPU speed is rarely an issue, it is too
                late, you've reinforced the meme "only C is good".

                I would challenge the assertion that *any* serious modern language is
                "very slow" on modern hardware in any meaningful sense. There are plenty
                of *specific tasks* which are too slow when written in one language or
                another, but that's not the same thing.


                --
                Steven.

                Comment

                • bearophileHUGS@lycos.com

                  #9
                  Re: Is python very slow compared to C

                  Steven D'Aprano>Very slow to do what, compared to what? The decay time
                  of the tau meson?<

                  Probably every answer I can give you is wrong for you, so answering is
                  almost useless... In this thread we have already given the most
                  pertinent answers to the original question from Diffuse.
                  I can show you this page, but I think this is useless too for you:


                  And, by the way, this is false:
                  Robert Hicks>Python is fast enough for just about anything you want to
                  do with it.<

                  If you are on a Unix-like OS, then the page about Weave from SciPy can
                  show you that sometimes Python isn't quick enough.

                  Bye,
                  bearophile

                  Comment

                  • bonono@gmail.com

                    #10
                    Re: Is python very slow compared to C


                    bearophileHUGS@ lycos.com wrote:[color=blue]
                    > Steven D'Aprano>Very slow to do what, compared to what? The decay time
                    > of the tau meson?<
                    >
                    > Probably every answer I can give you is wrong for you, so answering is
                    > almost useless... In this thread we have already given the most
                    > pertinent answers to the original question from Diffuse.
                    > I can show you this page, but I think this is useless too for you:
                    > http://shootout.alioth.debian.org/gp...on&lang2=ocaml
                    >[/color]

                    This is even more interesting:



                    However, to me, the strength of python is the batteries that is
                    included(and there are more and more coming).

                    Comment

                    • Felipe Almeida Lessa

                      #11
                      Re: Is python very slow compared to C

                      Em Dom, 2006-02-12 às 03:03 -0800, bearophileHUGS@ lycos.com escreveu:[color=blue]
                      > Probably every answer I can give you is wrong for you, so answering is
                      > almost useless... In this thread we have already given the most
                      > pertinent answers to the original question from Diffuse.
                      > I can show you this page, but I think this is useless too for you:
                      > http://shootout.alioth.debian.org/gp...on&lang2=ocaml[/color]

                      What they were saying is that at most of the times your program is going
                      to sit and wait for things like network, hard drive, user input, etc.,
                      and these cannot be changed by any language. Those benchmarks test only
                      raw CPU performance.

                      Yes, sometimes you *need* raw CPU power, but nobody said that in this
                      case Python is good for you. Python is good at making your life as a
                      programmer easier, and every Python programmer knows that.

                      I wanted to see PyRex or C modules versions of that benchmarks, it would
                      be really nice. This is the approach used to create fast CPU-bound
                      algorithms in Python, and as such should be tested as thoroughly as
                      those Python-only counterparts.

                      And if it matters for you: Google says Python is fast for them, what
                      else do you want?

                      Cya,
                      Felipe.

                      --
                      "Quem excele em empregar a força militar subjulga os exércitos dos
                      outros povos sem travar batalha, toma cidades fortificadas dos outros
                      povos sem as atacar e destrói os estados dos outros povos sem lutas
                      prolongadas. Deve lutar sob o Céu com o propósito primordial da
                      'preservação' . Desse modo suas armas não se embotarão, e os ganhos
                      poderão ser preservados. Essa é a estratégia para planejar ofensivas."

                      -- Sun Tzu, em "A arte da guerra"

                      Comment

                      • Jarek Zgoda

                        #12
                        Re: Is python very slow compared to C

                        diffuser78@gmai l.com napisa³(a):
                        [color=blue]
                        > I have just started to learn python. Some said that its slow. Can
                        > somebody pin point the issue.[/color]

                        So what? If you want fast code, go with assembly.

                        --
                        Jarek Zgoda

                        Comment

                        • Felipe Almeida Lessa

                          #13
                          Re: Is python very slow compared to C

                          Em Dom, 2006-02-12 às 03:20 -0800, bonono@gmail.co m escreveu:[color=blue]
                          > However, to me, the strength of python is the batteries that is
                          > included(and there are more and more coming).[/color]

                          So .NET is as good as Python? Hmmm... I think the language itself is the
                          best part of Python, its library is just a complement (a very good and
                          relevant one, though).

                          --
                          "Quem excele em empregar a força militar subjulga os exércitos dos
                          outros povos sem travar batalha, toma cidades fortificadas dos outros
                          povos sem as atacar e destrói os estados dos outros povos sem lutas
                          prolongadas. Deve lutar sob o Céu com o propósito primordial da
                          'preservação' . Desse modo suas armas não se embotarão, e os ganhos
                          poderão ser preservados. Essa é a estratégia para planejar ofensivas."

                          -- Sun Tzu, em "A arte da guerra"

                          Comment

                          • bonono@gmail.com

                            #14
                            Re: Is python very slow compared to C


                            Felipe Almeida Lessa wrote:[color=blue]
                            > Em Dom, 2006-02-12 às 03:20 -0800, bonono@gmail.co m escreveu:[color=green]
                            > > However, to me, the strength of python is the batteries that is
                            > > included(and there are more and more coming).[/color]
                            >
                            > So .NET is as good as Python? Hmmm... I think the language itself is the
                            > best part of Python, its library is just a complement (a very good and
                            > relevant one, though).[/color]
                            ..NET is not a language, IMO.

                            Comment

                            • Luis M. González

                              #15
                              Re: Is python very slow compared to C


                              Steven D'Aprano wrote:[color=blue]
                              > What is slow? Slow compared to what? Would you prefer to spend three days
                              > writing a program that will run in twenty milliseconds, or three hours
                              > writing the same program which runs in eighty milliseconds? Is the
                              > computer's execution time more important than your development time? If
                              > the computer's time is more valuable than your time, then you should be
                              > writing in assembly language.
                              >
                              > Python helps you write shorter code with fewer bugs, much quicker, than C.
                              > If you discover a specific problem that runs too slow in Python, it is
                              > possible to write a C extension to solve that specific problem, while
                              > still having all the other advantages of Python.[/color]

                              You are right, we all know that, but I think the person who asked this
                              question doesn't want to hear a sales pitch. He asked a very specific
                              question regarding execution speed.

                              Comment

                              Working...