Is a "real" C-Python possible?

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

    Is a "real" C-Python possible?

    I understand that the standard Python distribution is considered
    the C-Python. Howerver, the current C-Python is really a combination
    of C and Python implementation. There are about 2000 Python files
    included in the Windows version of Python distribution. I'm not sure
    how much of the C-Python is implemented in C but I think the more
    modules implemented in C, the better performance and lower memory
    footprint it will get.

    I wonder if it's possible to have a Python that's completely (or at
    least for the most part) implemented in C, just like PHP - I think
    this is where PHP gets its performance advantage. Or maybe I'm wrong
    because the core modules that matter are already in C and those Python
    files are really a think wrapper. Anyhow, if would be ideal if Python
    has performance similar to Java, with both being interpreted languages.

    Jack


  • Aahz

    #2
    Re: Is a "real&quot ; C-Python possible?

    In article <G62dnbBDl_Y0x8 HanZ2dnUVZ_gudn Z2d@comcast.com >,
    Jack <nospam@invalid .comwrote:
    >
    >I understand that the standard Python distribution is considered
    >the C-Python. Howerver, the current C-Python is really a combination
    >of C and Python implementation. There are about 2000 Python files
    >included in the Windows version of Python distribution. I'm not sure
    >how much of the C-Python is implemented in C but I think the more
    >modules implemented in C, the better performance and lower memory
    >footprint it will get.
    Prove it. ;-)

    Seriously, switching to more C code will cause development to bog down
    because Python is so much easier to write than C.
    >I wonder if it's possible to have a Python that's completely (or at
    >least for the most part) implemented in C, just like PHP - I think
    >this is where PHP gets its performance advantage. Or maybe I'm wrong
    >because the core modules that matter are already in C and those Python
    >files are really a think wrapper. Anyhow, if would be ideal if Python
    >has performance similar to Java, with both being interpreted languages.
    Could you provide some evidence that Python is slower than Java or PHP?
    --
    Aahz (aahz@pythoncra ft.com) <* http://www.pythoncraft.com/

    "Typing is cheap. Thinking is expensive." --Roy Smith

    Comment

    • Diez B. Roggisch

      #3
      Re: Is a &quot;real&quot ; C-Python possible?

      Jack schrieb:
      I understand that the standard Python distribution is considered
      the C-Python. Howerver, the current C-Python is really a combination
      of C and Python implementation. There are about 2000 Python files
      included in the Windows version of Python distribution. I'm not sure
      how much of the C-Python is implemented in C but I think the more
      modules implemented in C, the better performance and lower memory
      footprint it will get.
      >
      I wonder if it's possible to have a Python that's completely (or at
      least for the most part) implemented in C, just like PHP - I think
      this is where PHP gets its performance advantage. Or maybe I'm wrong
      because the core modules that matter are already in C and those Python
      files are really a think wrapper. Anyhow, if would be ideal if Python
      has performance similar to Java, with both being interpreted languages.
      Writing everything in C might be possible - but is a daunting task & not
      justified by the results. And wherever the standard libraries make use
      of the flexibility of Python, it's questionable if there really was any
      performance gain at all.

      But what REALLY is questionable is the alleged performance advantage -
      how do you back that up? According to the well-known (and surely
      limited) computer language shootout




      Python is roughly 25% faster than PHP. Granted, this is just one
      benchmark, with questionable real-life relevance. But where do you get
      the impression from that PHP is faster than Python then?

      diez

      Comment

      • Jack

        #4
        Re: Is a &quot;real&quot ; C-Python possible?

        >I'm not sure
        >>how much of the C-Python is implemented in C but I think the more
        >>modules implemented in C, the better performance and lower memory
        >>footprint it will get.
        >
        Prove it. ;-)
        I guess this is subjective :) - that's what I felt in my experience
        with web applications developed in Python and PHP. I wasn't able to
        find a direct comparison online.
        Seriously, switching to more C code will cause development to bog down
        because Python is so much easier to write than C.
        I understand. Python modules implemented in Python - this is how
        Python gets its really rich library.
        >>I wonder if it's possible to have a Python that's completely (or at
        >>least for the most part) implemented in C, just like PHP - I think
        >>this is where PHP gets its performance advantage. Or maybe I'm wrong
        >>because the core modules that matter are already in C and those Python
        >>files are really a thin wrapper. Anyhow, it would be ideal if Python
        >>has performance similar to Java, with both being interpreted languages.
        >
        Could you provide some evidence that Python is slower than Java or PHP?
        I think most Java-Python benchmarks you can find online will indicate
        that Java is a 3-10 times faster. A few here:



        Here's an article that shows the new version of Ruby is
        faster than Python in some aspects (they are catching up :)



        Comment

        • Jorge Godoy

          #5
          Re: Is a &quot;real&quot ; C-Python possible?

          Jack wrote:
          I wonder if it's possible to have a Python that's completely (or at
          least for the most part) implemented in C, just like PHP - I think
          this is where PHP gets its performance advantage. Or maybe I'm wrong
          PHP is slower than Python.

          Comment

          • Shadowsithe

            #6
            Re: Is a &quot;real&quot ; C-Python possible?

            That first article is five years old... I wouldn't give too much
            weight to it.

            Comment

            • Christian Heimes

              #7
              Re: Is a &quot;real&quot ; C-Python possible?

              Jack wrote:
              I guess this is subjective :) - that's what I felt in my experience
              with web applications developed in Python and PHP. I wasn't able to
              find a direct comparison online.
              Please compare the number of serious bugs and vulnerabilities in PHP and
              Python.
              I understand. Python modules implemented in Python - this is how
              Python gets its really rich library.
              Correct
              Python code is much easier to write and multiple times easier to get
              right than C code. Everybody with a few months of Python experience can
              contribute to the core but it requires multiple years of C and Python
              experience to contribute to the C implementation.
              I think most Java-Python benchmarks you can find online will indicate
              that Java is a 3-10 times faster. A few here:

              http://blog.snaplogic.org/?p=55
              There are lies, damn lies and benchmarks. :)

              Pure Python code is not going to beat Java code until the Python core
              gets a JIT compiler. If you want fair results you have to either
              disable the JIT in Java or use Psyco for Python. Otherwise you are
              comparing the quality of one language implementation to the quality of a
              JIT compiler.
              Here's an article that shows the new version of Ruby is
              faster than Python in some aspects (they are catching up :)
              http://antoniocangiano.com/2007/11/2...s-python-away/
              The Ruby developers are allowed to be proud. They were able to optimize
              some aspects of the implementation to get one algorithm about 14 times
              faster. That's good work. But why was it so slow in the first place?

              Nevertheless it is just one algorithm that beats Python in an area that
              is well known to be slow. Python's numbers are several factors slower
              than C code because the overhead of the dynamic language throws lots of
              data out of the cache line. If you need fast and highly optimized int
              and floating point operations you can rewrite the algorithm in C and
              create a Python interface for it.

              Comment

              • Christian Heimes

                #8
                Re: Is a &quot;real&quot ; C-Python possible?

                Jack wrote:
                I guess this is subjective :) - that's what I felt in my experience
                with web applications developed in Python and PHP. I wasn't able to
                find a direct comparison online.
                Please compare the number of serious bugs and vulnerabilities in PHP and
                Python.
                I understand. Python modules implemented in Python - this is how
                Python gets its really rich library.
                Correct
                Python code is much easier to write and multiple times easier to get
                right than C code. Everybody with a few months of Python experience can
                contribute to the core but it requires multiple years of C and Python
                experience to contribute to the C implementation.
                I think most Java-Python benchmarks you can find online will indicate
                that Java is a 3-10 times faster. A few here:

                http://blog.snaplogic.org/?p=55
                There are lies, damn lies and benchmarks. :)

                Pure Python code is not going to beat Java code until the Python core
                gets a JIT compiler. If you want fair results you have to either
                disable the JIT in Java or use Psyco for Python. Otherwise you are
                comparing the quality of one language implementation to the quality of a
                JIT compiler.
                Here's an article that shows the new version of Ruby is
                faster than Python in some aspects (they are catching up :)
                http://antoniocangiano.com/2007/11/2...s-python-away/
                The Ruby developers are allowed to be proud. They were able to optimize
                some aspects of the implementation to get one algorithm about 14 times
                faster. That's good work. But why was it so slow in the first place?

                Nevertheless it is just one algorithm that beats Python in an area that
                is well known to be slow. Python's numbers are several factors slower
                than C code because the overhead of the dynamic language throws lots of
                data out of the cache line. If you need fast and highly optimized int
                and floating point operations you can rewrite the algorithm in C and
                create a Python interface for it.

                Comment

                • Terry Reedy

                  #9
                  Re: Is a &quot;real&quot ; C-Python possible?


                  "Jack" <nospam@invalid .comwrote in message
                  news:G62dnbBDl_ Y0x8HanZ2dnUVZ_ gudnZ2d@comcast .com...
                  |I understand that the standard Python distribution is considered
                  | the C-Python. Howerver, the current C-Python is really a combination
                  | of C and Python implementation. There are about 2000 Python files
                  | included in the Windows version of Python distribution.

                  About half or fewer are modules meant to be imported into programs. The
                  rest comprise utility programs and test programs. The core interpreter is
                  all C.

                  | because the core modules that matter are already in C

                  Correct. There are about 20 'builtin' modules written is C either because
                  they need low level access to the machine or for speed concerns. Third
                  party modules not included in the standard distribution but definitely part
                  of the Python universe are also a mix.

                  If people wrote everything in C for speed, there would be no need for
                  Python!!

                  And don't say that you want everyone else to write in C while you enjoy the
                  pleasures of Python ;-).

                  tjr



                  Comment

                  • Jack

                    #10
                    Re: Is a &quot;real&quot ; C-Python possible?

                    >I think most Java-Python benchmarks you can find online will indicate
                    >that Java is a 3-10 times faster. A few here:
                    >http://mail.python.org/pipermail/pyt...ry/125789.html
                    >http://blog.snaplogic.org/?p=55
                    >
                    There are lies, damn lies and benchmarks. :)
                    >
                    Pure Python code is not going to beat Java code until the Python core
                    gets a JIT compiler. If you want fair results you have to either
                    disable the JIT in Java or use Psyco for Python. Otherwise you are
                    comparing the quality of one language implementation to the quality of a
                    JIT compiler.
                    The second articple does have a column for Psyco. It helps in some areas
                    but still not good enough to stand up against Java. Plus, Psyco is not the
                    main stream and has stopped development.

                    I'm also wondering, if Psyco is the right way to do, any reason it's not
                    being integrated into standard Python?


                    Comment

                    • Paul McGuire

                      #11
                      Re: Is a &quot;real&quot ; C-Python possible?

                      On Dec 9, 6:07 pm, "Jack" <nos...@invalid .comwrote:
                      Plus, Psyco is not the
                      main stream and has stopped development.
                      >
                      <scooby-whruu??>

                      What makes you think it has stopped development? I just swung by the
                      SF project page, and its most recent news post was just 2 months ago.

                      Psyco may not be in the standard Python distribution, but it is
                      definitely a fixture of the Python landscape, which is about as close
                      to main stream as you can get.

                      -- Paul

                      Comment

                      • Chris M

                        #12
                        Re: Is a &quot;real&quot ; C-Python possible?

                        On Dec 9, 10:04 pm, Paul McGuire <pt...@austin.r r.comwrote:
                        On Dec 9, 6:07 pm, "Jack" <nos...@invalid .comwrote:
                        >
                        Plus, Psyco is not the
                        main stream and has stopped development.
                        >
                        <scooby-whruu??>
                        >
                        What makes you think it has stopped development? I just swung by the
                        SF project page, and its most recent news post was just 2 months ago.
                        >
                        Psyco may not be in the standard Python distribution, but it is
                        definitely a fixture of the Python landscape, which is about as close
                        to main stream as you can get.
                        >
                        -- Paul
                        Maybe because of this line:

                        "Psyco is a reasonably complete project. I will not continue to
                        develop it beyond making sure it works with future versions of Python.
                        My plans for 2006 are to port the techniques implemented in Psyco to
                        PyPy. PyPy will allow us to build a more flexible JIT specializer,
                        easier to experiment with, and without the overhead of having to keep
                        in sync with the evolutions of the Python language."

                        Comment

                        • Bruno Desthuilliers

                          #13
                          Re: Is a &quot;real&quot ; C-Python possible?

                          Jack a écrit :
                          I understand that the standard Python distribution is considered
                          the C-Python. Howerver, the current C-Python is really a combination
                          of C and Python implementation. There are about 2000 Python files
                          included in the Windows version of Python distribution. I'm not sure
                          how much of the C-Python is implemented in C but I think the more
                          modules implemented in C, the better performance and lower memory
                          footprint it will get.
                          >
                          I wonder if it's possible to have a Python that's completely (or at
                          least for the most part) implemented in C, just like PHP - I think
                          this is where PHP gets its performance advantage.
                          Which "performanc e advantage" ???
                          Or maybe I'm wrong
                          because the core modules that matter are already in C and those Python
                          files are really a think wrapper. Anyhow, if would be ideal if Python
                          has performance similar to Java, with both being interpreted languages.
                          <mode="pedantic ">
                          Neither Python nor Java are "interprete d languages", because there's no
                          such thing as an "interprete d language" - being 'interpreted' (whatever
                          the definition of 'interpreted') is a quality of an implementation, not
                          of a language. wrt/ to CPython and Sun's Java implementation, they are
                          both byte-code compiled - which, according to usual definitions, is not
                          quite the same thing !-)
                          </mode>

                          Now most of the performance difference is due to Java being much less
                          dynamic than Python, which allow both the compiler and the VM to do much
                          more optimizations - specially JIT compilation. It's quite harder to
                          implement such optimizations for a language as dynamic as Python (IIRC,
                          some language/compiler gurus here mentionned that even compiling Python
                          to native binary code would not buy that much gain).

                          Actually, it seems that taking the opposite approach - that is, trying
                          to implement as much as possible of Python in Python - would be more
                          promising wrt/ possible JIT compilation, cf the Pypy project.

                          Comment

                          • Paul Boddie

                            #14
                            Re: Is a &quot;real&quot ; C-Python possible?

                            On Dec 9, 10:43 pm, "Jack" <nos...@invalid .comwrote:There's some choice nonsense here, albeit on a different topic:

                            "Coding for wxwidgets, using a QT or GTK bridge, or using TCL/TK is
                            hardly an optimal solution when writing complex graphical
                            applications, and Java wins in this area, despite there comically
                            being many problems with the look and feel of Java applications."

                            Clearly an individual who hasn't actually used any of the Python GUI
                            development solutions, given the choice of words: "bridge", "hardly an
                            optimal solution"; virtually intimating that you'd be doing malloc/
                            free or new/delete all the time. Plus throwaway remarks of the form
                            "XYZ wins" tend to suggest beliefs with little substance and a
                            continual need for self-reassurance on such matters.

                            Anyway, back to the topic at hand...
                            Here's an article that shows the new version of Ruby is
                            faster than Python in some aspects (they are catching up :)
                            >
                            http://antoniocangiano.com/2007/11/2...19-smokes-pyth...
                            It's evident that the next mainstream version of Ruby will have
                            various optimisations around recursive operations - something that has
                            generally been rejected for CPython. Of course, the mainstream Ruby
                            implementation has had a lot of scope for improvement:



                            What disappoints me somewhat is that most of the people interested in
                            taking Python performance to the next level are all outside (or on the
                            outer fringes of) the CPython core development group: PyPy and Shed
                            Skin are mostly distinct technologies; Psyco integrates with CPython
                            but hasn't improved the "out of the box" situation; Pyrex is really a
                            distinct tool, being more like a convenient wrapper generator than a
                            bolt-on high performance engine for CPython. Language implementations
                            like that of Lua have seen more progress on integrating solutions for
                            performance, it would seem.

                            As for a C-Python of the form requested, I suppose tools like Shed
                            Skin and RPython fit the bill somewhat, if a transparent solution is
                            needed where one writes in Python and it magically becomes fairly
                            efficient C or C++. Otherwise, Pyrex provides more explicit control
                            over what gets written in C and what remains in Python.

                            Paul

                            Comment

                            • hunter.grubbs@gmail.com

                              #15
                              Re: Is a &quot;real&quot ; C-Python possible?

                              On Dec 9, 3:23 pm, a...@pythoncraf t.com (Aahz) wrote:
                              In article <G62dnbBDl_Y0x8 HanZ2dnUVZ_gudn ...@comcast.com >,
                              >
                              Jack <nos...@invalid .comwrote:
                              >
                              I understand that the standard Python distribution is considered
                              the C-Python. Howerver, the current C-Python is really a combination
                              of C and Python implementation. There are about 2000 Python files
                              included in the Windows version of Python distribution. I'm not sure
                              how much of the C-Python is implemented in C but I think the more
                              modules implemented in C, the better performance and lower memory
                              footprint it will get.
                              >
                              Prove it. ;-)
                              >
                              Seriously, switching to more C code will cause development to bog down
                              because Python is so much easier to write than C.
                              >
                              I wonder if it's possible to have a Python that's completely (or at
                              least for the most part) implemented in C, just like PHP - I think
                              this is where PHP gets its performance advantage. Or maybe I'm wrong
                              because the core modules that matter are already in C and those Python
                              files are really a think wrapper. Anyhow, if would be ideal if Python
                              has performance similar to Java, with both being interpreted languages.
                              >
                              Could you provide some evidence that Python is slower than Java or PHP?
                              --
                              Aahz (a...@pythoncra ft.com) <* http://www.pythoncraft.com/
                              >
                              "Typing is cheap. Thinking is expensive." --Roy Smith
                              I'd like to provide some evidence that Python is *faster* than Java.
                              EVE online...emulat e that in JAVA please.

                              Comment

                              Working...