Is a "real" C-Python possible?

J

Jack

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
 
A

Aahz

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?
 
D

Diez B. Roggisch

Jack said:
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

http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all


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
 
J

Jack

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.
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:
http://mail.python.org/pipermail/python-list/2002-January/125789.html
http://blog.snaplogic.org/?p=55

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/28/holy-shmoly-ruby-19-smokes-python-away/
 
J

Jorge Godoy

Jack said:
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.
 
S

Shadowsithe

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

Christian Heimes

Jack said:
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://mail.python.org/pipermail/python-list/2002-January/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.
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/28/holy-shmoly-ruby-19-smokes-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.
 
C

Christian Heimes

Jack said:
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://mail.python.org/pipermail/python-list/2002-January/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.
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/28/holy-shmoly-ruby-19-smokes-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.
 
T

Terry Reedy

|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
 
J

Jack

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?
 
P

Paul McGuire

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
 
T

Terry Reedy

| 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.

It further development is effectively part of the PyPy project, which
includes some jit work.

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

It does not accelerate everything and may slow somethings, it was (is?)
not compatible with everything, it bloats space requirements, it competes
with C/Fortran coded extensions (such as NumPy), it was originally I386
specific, its development cycle was much faster than Python's release
cycle, ...

The cutoff between what goes in the core/stdlib is arbitrary in borderline
cases, but some cutoff is necessary.

tjr
 
C

Chris M

<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."
 
C

C. ARA

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.

to compare the speed of the two u need a lot of normalization, it is
completely two different vector quantities --irrational. There is no way
for an absolute comparison.

both php and python are excellent but each has some application in which
it defeats the other..

if u want something really fast use assembly.. what??? why are u
shocked!! you don't want to pay tax ;)

it's a matter of preference and need after all.. don't be misled by all
the fuss about speed or the mightiness of any programming language they
are just tools .. u r the secret!!
 
B

Bruno Desthuilliers

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 "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.

<mode="pedantic">
Neither Python nor Java are "interpreted languages", because there's no
such thing as an "interpreted 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.
 
P

Paul Boddie


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/28/holy-shmoly-ruby-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:

http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=all

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
 
H

hunter.grubbs

Prove it. ;-)

Seriously, switching to more C code will cause development to bog down
because Python is so much easier to write than C.


Could you provide some evidence that Python is slower than Java or PHP?

I'd like to provide some evidence that Python is *faster* than Java.
EVE online...emulate that in JAVA please.
 
R

Raymond Hettinger

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.

-1 This would seriously muck-up the evolution of the language.
Having a few building blocks written in C provides a basis
for writing very fast pure python (for example, sets, heapq,
itertools).
Beyond those building blocks, it is a step backwards to write in C.

Also, if you really need performance, the traditional solutions are to
use tools like Psyco or Pyrex.


Raymond
 
H

hdante

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?

Instead of recurring to benchmarks, I recommend that you read the
following:

http://highscalability.com/youtube-architecture

There are no comparisons there, just a sample of what python and
psyco can achieve. For a language that isn't designed with speed in
mind, I think that's quite impressive.
 
B

Bruno Desthuilliers

Jack a écrit :
I guess this is subjective :)

If yes, benchmarks are not an argument. Else, you'll have hard time
making your point !-)

(hint: doing objective benchmarking is really a difficult art)
- 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.

Could it be the case that you are comparing Python CGI scripts with
mod_php ? Anyway, since php is also usable (hem... maybe not the
appropriate qualificative) outside Apache, it should quite easy to make
a more serious test ?

Seriously: I never saw any benchmark where php was faster than Python
for any kind of stuff - unless of course you're trying to compare Zope
running as a CGI script with an hello world PHP script runned by mod_php.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top