Thanks!
Stephen
> Anyone know which is faster? I'm a PHP programmer but considering
> getting into Python ...
faster for what? in my experience, people can hack into a PHP site in
no time at all, but maybe you meant something else?
(seriously, it depends on what you're doing, of course. and how you're
running your programs. and what kind of programs you're writing. and
what frameworks you're using. and, and. and, ...)
</F>
Relative in Python (and for local use), PHP is a tortoise with of a hand
brake.
In terms of development, Python is a far better language to write code
in[1], has a much more mature standard library[2] and an excellent
community[3].
I've avoided your original question. Speed. Python is faster to
develop in, and is on-par with execution time. The trick is, with
python, you can trivially profile your application and re-write any
sections of code that are too slow in C, in pyrex, optimise them with
psyco, or just plain fix your efficiency problems.
Profiling in php isn't as easy as
import profile
profile.run("main()")
Regards,
Stephen Thorne.
[1] I have written php commerically for over 3 years. This isn't a
subjective look-from-afar. I actually know from down and dirty day-in
day-out experience.
[2] compare http://pear.php.net to "apt-cache search ^python"
[3] Look at http://bugs.php.net/ . There's something fundamentally
wrong with a language community where people who have stumbled on
honest-to-god bugs are abused.
For web service, the first hurdle is picking which python web interface
to use, installing it and (if necessary) configuring your web server to
use it. (All that choice is great in many respects, but it does
complicate getting started.)
Anyway, once you've done that, i doubt you'll find any speed issues with
python, and it is a more pleasant language than PHP. (Unfortunately,
that initial hurdle can be a big one; I am still using PHP on my server
because I never cleared it.)
-- Russell
> Anyone know which is faster? I'm a PHP programmer but considering
> getting into Python ...
Python application servers (Webware, Skunkweb) can work much faster than
php. But it is true only for non-trivial code. Benchmark for "Hello world"
is a nonsense of course.
But pure speed is not the all. Python can scale better, has cleaner and
consistent syntax, better standard libraries and is a common language
rather than specific script language for web only.
--
JZ
If a system is fast enough on a single processor, it doesn't need to scale.
Is PHP too slow for your needs ? Is that the reason for changing ? If it
is, then Python might not satisfy your need. If it isn't, have you
thought about why you want to use Python ? If you have, are there
greater benefits in total over PHP from what you understand of both PHP
and PYthon.
Not sure where you are currently at with your evaluation of Python so if
you could outline a few more points on your needs, wants, and
expectations it would help when answering your questions about Python.
Huy
I think he means, "scale to larger programs," not "scale to more
processors."
--
Robert Kern
rk...@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Your point is circular; "fast enough (right now)" can be defined as
"doesn't need to scale (right now)".
For any given server app, enough clients will bog it down. If you're
trying to claim that PHP has less trouble with this, I've seen a lot of
PHP sites go down under load, so it is clearly not a non-issue.
Python's scaling isn't automatic, it's just easier to do.
I've never heard of any large sites being done in Python, with or
without scaling. By a large site I mean one that regularly gets 100
hits/sec or more. There are many sites like that out there. Those
are the ones that need to be concerned about scaling.
For sites that get less traffic than that, they only reason they need
to scale if they're written in Python is that Python is too slow.
> For sites that get less traffic than that, they only reason they need
> to scale if they're written in Python is that Python is too slow.
Asked earnestly: is there a feel or quantification that Python is slower than PHP in network applications?
If, so, I am wondering if it is because of the traction PHP has in the web community leading to possibly tighter integration with (e.g.) Apache.
My beloved Python-oriented webhost doesn't currently support Mod-Python due to concerns about unknown security risks, and without that one carries the interpreter start-up burden for each invocation, as I understand it. Speed in a server-client environment does concern me a bit because 100+ hits per second would be the minimum realm of success for the web app I am building in Python (I do not foresee using PHP, so maybe I would convert everything to C++ if I had to, but I really would not want to have to...)
In everything I have done so far, Python's speed has been quite satisfactory, and I always remember the loud complainings in the MySQL forum about SQL queries that take seconds, minutes, days... only to end up magnitudes faster when someone points out the folly of the code or table set-up.
Not sure if the OP is considering Python v.s. PHP on the server or on the desktop (PHP isn't web only, except by common use); they are very different use cases.
Eric Pederson
http://www.songzilla.blogspot.com
:::::::::::::::::::::::::::::::::::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::::::::::::::::::::::::::::::::::
Others have answered interpretations of your question other than
execution speed. I can't give you numbers on that - you'd probably have
to do some benchmarks yourself - but can offer a few suggestions.
First, Python can be _seriously_ fast for web use. You need to make sure
you're not starting and terminating interpreters all the time, so you'll
need to use a Python embedded web server proxied by Apache (like Zope
does), SCGI (as works well with Quixote), Twisted, or some other way of
running your code persistently. Persistent CGI usually means worrying
about memory leaks, but unless you're using flakey C extension modules
that shouldn't be a problem with Python.
If you have your Python code running as some sort of persistent server,
then you can use tools like Psyco to get a further (often very
impressive) speed boost. The biggest speed-up with Pysco that I've
clocked is 20x, but 3x - 5x is fairly common.
Whether it'll be faster or slower than PHP, I just can't guess. I think
it'd certainly be well worth a try, especially if you're writing any
more complex applications.
That said, for 90% of users development time matters more than execution
speed, and that's another matter entirely.
--
Craig Ringer
>> But pure speed is not the all. Python can scale better,
>
> If a system is fast enough on a single processor, it doesn't need to scale.
the word "scale" doesn't necessarily imply performance. software developers
also deal with scales like program size, application complexity, team size, number
of external systems, etc.
</F>
> I think he means, "scale to larger programs," not "scale to more
> processors."
Yes. I will try to be more specific. There is several reasons why Python
scales better than PHP.
(1) Python uses namespaces, PHP - not. The bigger programm the bigger
probability of conflict among names in PHP.
(2) Not only PHP lacks namespaces. It has one big inconsistent mess with
its function naming! Inconsistent prefixes, order of parameters. Mess. It
is difficult to memorize it. Python programming need less interupting for
reading manual.
(3) Python uses modules, PHP - not. Python can download single or some
classes from many big modules (eg. from module1 import class1, var1, fun1).
PHP is primitive in its copy-paste *all* included files! So Python uses
less memory than PHP and do not need to parse so many lines.
(4) Python automatic compile every imported modules into bytecode, PHP has
to parse all those mess. Without accelerators PHP is much slower for bigger
applications. This is the reason why PEAR is so slow. This is the reason
why ezPublish is so slow. The bigger code (more included files), the slower
PHP works.
(5) Python compile its modules automatic and do not need to parse them for
every browser request like PHP do.
(6) Pythonic application server (eg. Webware) do not need to load and parse
any files from filesystem at all! It loads them once, compile it and store
compiled scripts in memory. PHP has to load files from filesystem, parse
them and execute. From my own experience: when I moved from PHP to Webware
and I compared its performance with (similar scale) php appplications, my
webware was almost 6 times faster!
(7) Python has much better free IDE editors with graphic debugger inside.
PythonWin, Boa, SPE, Eric3 etc. It is much easier debug in Python than i
PHP for larger programmes.
(8) And last but not least. Python is truly object oriented, general
purpose language. PHP is not general purpose language. PHP4 has very poor
OO. (PHP5 has better, but has also some useless new features like private
variables. They have sense for static compiled languages like C++ or Java ,
not for dynamic ones.) Python also uses sofisticated exception handling,
uses namespaces, has module import, has better unicode support, has more
consistent api etc.
One more example from my experience. I always have problem with converting
string among iso-8859-2, cp1250, mac-ce and utf-8. PHP utf8 functions are
poor, implements useless (for me) iso-8859-1 only. iconv library for PHP is
even worse, when it cannot convert some characters it deletes the following
characters! PHP has no such like: unicode(txt, 'cp1250').encode('cp1250',
'xmlcharrefreplace'). When some characters exists only in cp1250 but not in
iso-8859-2 that function convert them into xml entity &#number; Cute!
--
JZ ICQ:6712522
http://zabiello.com
You can always do what I did. I wrote the backend of my app in Python
and run it as an XML-RPC server. I did the front end in PHP using the
Smarty template tool. (The actual templates themselves were stored
in the Python server and grabbed via XML-RPC). Effectively PHP/Smarty
were formatting XML-RPC results, delivered as Python dicts which turn
into Smarty arrays (and it all works fine with nested lists and dicts).
That way I got the best of both worlds, didn't have to get mod-python
installed, and *my opinion* is that Smarty is the nicest template tool
I have tried in Python or PHP.
Roger
>(3) Python uses modules, PHP - not. Python can download single or some
>classes from many big modules (eg. from module1 import class1, var1, fun1).
>PHP is primitive in its copy-paste *all* included files! So Python uses
>less memory than PHP and do not need to parse so many lines.
>
>
Not that I'm disagreeing with your overall premise here, that Python
scales better, but this particular point appears to contain (or at least
encourage) some misconceptions.
Yes, Python can import only one or two functions/classes from a large
module. But in order to do that, the entire module must be imported and
loaded into sys.modules, and then individual elements of that module are
bound to names in the current namespace. You're not actually saving any
memory or parsing time by only importing a few names, because
from module1 import class1
hass effectively the same end result as
import module1
class1 = module1.class1
del module1
(except that the former is a few less changes in the current
namespace). The performance advantages of importing only one or two
names are quite minimal; the only real reason to do it is to save typing
and to have code that might be seen as 'cleaner' (though the latter is a
debatable point, depending on specific circumstances).
Jeff Shannon
Technician/Programmer
Credit International
We're mainly using it to drive dynamic web apps ... online store ...
etc.
Thanks Again!
Stephen
If you want portions of your code in C, then wrap them with Swig.
That way they can be available in any number of languages including
Python, PHP, Java and Perl.
http://www.swig.org/compare.html
Roger
> I've never heard of any large sites being done in Python, with or
> without scaling. By a large site I mean one that regularly gets 100
> hits/sec or more. There are many sites like that out there. Those
> are the ones that need to be concerned about scaling.
How exactly would you know which large sites are using Python? The PHP
sites tend to advertise their use of PHP by file extensions on every URL,
but a lot of Python sites don't.
I don't know how to tell how many hits a random site has, but there are
certainly some big users out there. For example Viacom uses Zope for many
of its CBS and UPN websites. LastMinute.com, who definitely hit your large
site definition, were working with Zope as well although so far as I know
nothing has yet reached their live site.
If you're talking about usage as a server side scripting
language, then PHP will likely give better page serving
throughput for the same hardware configuration versus
even something that is mod_python based (but I believe
the speed diff would be well under 100%).
However, Python is just so much superior as a language (I
was deep into PHP before I tried out Python and I always hate
having to go back to PHP nowadays in the cases where it is
unavoidable) that you will still want to use Python even if
PHP requires lower server specs to handle the same throughput.
Also, if you have a more complex application for which
pooled variable reuse is an important performance-determining
factor, Python-based server-side scripting solutions might
offer better control of this aspect and may thus yield
superior performance to a PHP-based one.
The real problem with Python is not speed but _availability_.
The number of hosting services out there supporting mod_php
completely outstrips those supporting mod_python. Moreover, they
are significantly cheaper, and offer a lot more features
(Fantastico, etc...). The python-based hosting solutions
out there tend to be dedicated to Python and thus do not
offer these solutions.
If this is not an issue (i.e. you will be running your
own server), then I highly recommend going the Python
route using something like Spyce (which is the closest
thing to PHP in the Python world).
> If you're talking about usage as a server side scripting
> language, then PHP will likely give better page serving
> throughput for the same hardware configuration versus
> even something that is mod_python based (but I believe
> the speed diff would be well under 100%).
I have different experience. When I moved from PHP to Webware
and I compared its performance with (similar scale) php appplications,
my webware was almost 6 times faster! Application servers are always
faster because they use compiled scripts stored in memory. They do not need
to load files from filesystem nor parse them. PHP is faster only for
trivial, useless benchmarks like "Hello world". For bigger code Python is
faster than PHP.
> The real problem with Python is not speed but _availability_.
You have rigth here.
--
JZ