I posted this few weeks ago (remember the C Sharp thread?) but it went
unnoticed on the large mass of posts, so let me retry. Here I get Python+
Psyco twice as fast as optimized C, so I would like to now if something
is wrong on my old laptop and if anybody can reproduce my results.
Here are I my numbers for calling the error function a million times
(Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz):
$ time p23 erf.py
real 0m0.614s
user 0m0.551s
sys 0m0.029s
This is twice as fast as optimized C:
$ gcc erf.c -lm -o3
$ time ./a.out
real 0m1.125s
user 0m1.086s
sys 0m0.006s
Here is the situation for pure Python
$time p23 erf.jy
real 0m25.761s
user 0m25.012s
sys 0m0.049s
and, just for fun, here is Jython performance:
$ time jython erf.jy
real 0m42.979s
user 0m41.430s
sys 0m0.361s
The source code follows (copied from Alex Martelli's post):
----------------------------------------------------------------------
$ cat erf.py
import math
import psyco
psyco.full()
def erfc(x):
exp = math.exp
p = 0.3275911
a1 = 0.254829592
a2 = -0.284496736
a3 = 1.421413741
a4 = -1.453152027
a5 = 1.061405429
t = 1.0 / (1.0 + p*x)
erfcx = ( (a1 + (a2 + (a3 +
(a4 + a5*t)*t)*t)*t)* t ) * exp(-x*x)
return erfcx
def main():
erg = 0.0
for i in xrange(1000000) :
erg += erfc(0.456)
if __name__ == '__main__':
main()
--------------------------------------------------------------------------
# python/jython version = same without "import psyco; psyco.full()"
--------------------------------------------------------------------------
$cat erf.c
#include <stdio.h>
#include <math.h>
double erfc( double x )
{
double p, a1, a2, a3, a4, a5;
double t, erfcx;
p = 0.3275911;
a1 = 0.254829592;
a2 = -0.284496736;
a3 = 1.421413741;
a4 = -1.453152027;
a5 = 1.061405429;
t = 1.0 / (1.0 + p*x);
erfcx = ( (a1 + (a2 + (a3 +
(a4 + a5*t)*t)*t)*t)* t ) * exp(-x*x);
return erfcx;
}
int main()
{
double erg=0.0;
int i;
for(i=0; i<1000000; i++)
{
erg = erg + erfc(0.456);
}
return 0;
}
Michele Simionato, Ph. D. Mi************* *@libero.it http://www.phyast.pitt.edu/~micheles
--- Currently looking for a job --- 18 4890
Michele Simionato wrote: I posted this few weeks ago (remember the C Sharp thread?) but it went unnoticed on the large mass of posts, so let me retry. Here I get Python+ Psyco twice as fast as optimized C, so I would like to now if something is wrong on my old laptop and if anybody can reproduce my results.
I can. :-)
I had to increase the loop counter by a factor of 10 because it
ran too fast on my machine (celeron 533 mhz), and added a print statement
of the accumulated sum (erg). These are my results:
[irmen@atlantis]$ gcc -O3 -march=pentium2 -mcpu=pentium2 -lm erf.c
[irmen@atlantis]$ time ./a.out
5190039.338694
4.11user 0.00system 0:04.11elapsed 99%CPU (0avgtext+0avgd ata 0maxresident)k
0inputs+0output s (103major+13min or)pagefaults 0swaps
[irmen@atlantis]$ time python2.3 erf.py
5190039.33869
2.91user 0.01system 0:02.92elapsed 99%CPU (0avgtext+0avgd ata 0maxresident)k
0inputs+0output s (544major+380mi nor)pagefaults 0swaps
This is with gcc 3.2.2 on Mandrake 9.1.
While Python + Psyco is not twice as fast as compiled & optimized C,
it's still faster by almost 30% on my system, which is still great!!
--Irmen
Michele Simionato wrote: I posted this few weeks ago (remember the C Sharp thread?) but it went unnoticed on the large mass of posts, so let me retry. Here I get Python+ Psyco twice as fast as optimized C, so I would like to now if something is wrong on my old laptop and if anybody can reproduce my results.
I can. :-)
I had to increase the loop counter by a factor of 10 because it
ran too fast on my machine (celeron 533 mhz), and added a print statement
of the accumulated sum (erg). These are my results:
[irmen@atlantis]$ gcc -O3 -march=pentium2 -mcpu=pentium2 -lm erf.c
[irmen@atlantis]$ time ./a.out
5190039.338694
4.11user 0.00system 0:04.11elapsed 99%CPU (0avgtext+0avgd ata 0maxresident)k
0inputs+0output s (103major+13min or)pagefaults 0swaps
[irmen@atlantis]$ time python2.3 erf.py
5190039.33869
2.91user 0.01system 0:02.92elapsed 99%CPU (0avgtext+0avgd ata 0maxresident)k
0inputs+0output s (544major+380mi nor)pagefaults 0swaps
This is with gcc 3.2.2 on Mandrake 9.1.
While Python + Psyco is not twice as fast as compiled & optimized C,
it's still faster by almost 30% on my system, which is still great!!
--Irmen
Michele Simionato wrote: $ time p23 erf.py real 0m0.614s user 0m0.551s sys 0m0.029s
This is twice as fast as optimized C:
$ gcc erf.c -lm -o3 $ time ./a.out real 0m1.125s user 0m1.086s sys 0m0.006s
Here is the situation for pure Python
$time p23 erf.jy real 0m25.761s user 0m25.012s sys 0m0.049s
and, just for fun, here is Jython performance:
$ time jython erf.jy real 0m42.979s user 0m41.430s sys 0m0.361s
Mmm...on my machine C is faster. What version of GCC do you have? I think
2.9x, right?
These are my timings (Debian GNU Linux Unstable, Duron 1300, Python2.3,
Psyco CVS, GCC 3.3.2, Java 1.4.1):
$ time python erf.py
real 0m0.251s
user 0m0.207s
sys 0m0.012s
$ gcc erf.c -lm -O3
$ time ./a.out
real 0m0.162s
user 0m0.157s
sys 0m0.001s
Notice that C is faster than Psyco + Python2.3 on my machine (about 65% of
speedup)
Without Psyco Python2.3 tooks about 6 seconds
$ time python erf.jy
real 0m6.177s
user 0m6.040s
sys 0m0.010s
And Jython is definitely slower :)
$ time jython erf.jy
real 0m10.423s
user 0m9.506s
sys 0m0.197s
--
Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rh****@NOSPAMmy self.com
Michele Simionato wrote: $ time p23 erf.py real 0m0.614s user 0m0.551s sys 0m0.029s
This is twice as fast as optimized C:
$ gcc erf.c -lm -o3 $ time ./a.out real 0m1.125s user 0m1.086s sys 0m0.006s
Here is the situation for pure Python
$time p23 erf.jy real 0m25.761s user 0m25.012s sys 0m0.049s
and, just for fun, here is Jython performance:
$ time jython erf.jy real 0m42.979s user 0m41.430s sys 0m0.361s
Mmm...on my machine C is faster. What version of GCC do you have? I think
2.9x, right?
These are my timings (Debian GNU Linux Unstable, Duron 1300, Python2.3,
Psyco CVS, GCC 3.3.2, Java 1.4.1):
$ time python erf.py
real 0m0.251s
user 0m0.207s
sys 0m0.012s
$ gcc erf.c -lm -O3
$ time ./a.out
real 0m0.162s
user 0m0.157s
sys 0m0.001s
Notice that C is faster than Psyco + Python2.3 on my machine (about 65% of
speedup)
Without Psyco Python2.3 tooks about 6 seconds
$ time python erf.jy
real 0m6.177s
user 0m6.040s
sys 0m0.010s
And Jython is definitely slower :)
$ time jython erf.jy
real 0m10.423s
user 0m9.506s
sys 0m0.197s
--
Lawrence "Rhymes" Oluyede http://loluyede.blogspot.com rh****@NOSPAMmy self.com
Michele Simionato wrote: I posted this few weeks ago (remember the C Sharp thread?) but it went unnoticed on the large mass of posts, so let me retry. Here I get Python+ Psyco twice as fast as optimized C
$ gcc erf.c -lm -O3
try a 3.x series gcc with the appropriate -march=pentium3
You'll be pleasently surprised. I can't understand how
the sudden improvment of gcc code generation lately hasn't
been hyped more? If you want to try different machines
then http://www.pixelbeat.org/scripts/gcccpuopt will give
you the appropriate machine specific gcc options to use.
Note also -ffast-math might help a lot in this application?
cheers,
Pádraig.
Michele Simionato wrote: I posted this few weeks ago (remember the C Sharp thread?) but it went unnoticed on the large mass of posts, so let me retry. Here I get Python+ Psyco twice as fast as optimized C
$ gcc erf.c -lm -O3
try a 3.x series gcc with the appropriate -march=pentium3
You'll be pleasently surprised. I can't understand how
the sudden improvment of gcc code generation lately hasn't
been hyped more? If you want to try different machines
then http://www.pixelbeat.org/scripts/gcccpuopt will give
you the appropriate machine specific gcc options to use.
Note also -ffast-math might help a lot in this application?
cheers,
Pádraig.
Irmen de Jong <irmen@-NOSPAM-REMOVETHIS-xs4all.nl> writes: P@draigBrady.co m wrote:
try a 3.x series gcc with the appropriate -march=pentium3 You'll be pleasently surprised.
In my other reply I mentioned that I still get a Python+Psyco advantage of 30% over a gcc 3.2.2 compiled version. My gcc is doing a lot better than Michele's reported 50% difference, but Python+Psyco still wins :-)
So, the interesting part is: why?
John
Irmen de Jong <irmen@-NOSPAM-REMOVETHIS-xs4all.nl> writes: P@draigBrady.co m wrote:
try a 3.x series gcc with the appropriate -march=pentium3 You'll be pleasently surprised.
In my other reply I mentioned that I still get a Python+Psyco advantage of 30% over a gcc 3.2.2 compiled version. My gcc is doing a lot better than Michele's reported 50% difference, but Python+Psyco still wins :-)
So, the interesting part is: why?
John
On Sun, 24 Aug 2003 00:31:15 +0100, John J. Lee wrote: Irmen de Jong <irmen@-NOSPAM-REMOVETHIS-xs4all.nl> writes:
P@draigBrady.co m wrote:
.... but Python+Psyco still wins :-)
So, the interesting part is: why?
John
My suspicion is that when psyco looks at erfc, it
finds that nothing changes and so replaces the
function call with the resulting number (am i right? it's the
same each time?). This is what a "specializi ng compiler"
would do, me thinks. So, try using a different number
with each call.
Simon. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michele Simionato |
last post by:
I posted this few weeks ago (remember the C Sharp thread?) but it went
unnoticed on the large mass of posts, so let me retry. Here I get Python+
Psyco twice as fast as optimized C, so I would like to now if something
is wrong on my old laptop and if anybody can reproduce my results.
Here are I my numbers for calling the error function a million times
(Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz):
$ time p23 erf.py
real ...
|
by: Michael Scarlett |
last post by:
There is an amazing article by paul graham about python, and an even
better discussion about it on slashdot. The reason I point this out,
is the more I read both articles, the more I realised how we would be
mutilating the language with that god forsaken @ decorator.
I don't know about the rest of you, but I learned python and fell in
love with its syntax and simplicity. Python - just works. So please
GVR. Don't complicate it. Leave it as...
|
by: julio |
last post by:
Sorry but there is no another way, c# .net and mono are going to rip
python, not because python is a bad lenguage, but because is to darn old
and it refuses to innovate things, to fix wrong things, just because
retarded backwards compatibility and because the python comunity and
developers refuses to consider tools as being almost as important as the
language itself.
What does c# .net has that python doesnt ? (significant features)
--...
|
by: Iwan van der Kleyn |
last post by:
Please ignore if you are allergic to ramblings :-)
Despite a puritan streak I've always tried to refrain from language wars
or syntax bickering; call it enforced pragmatism. That's the main reason
why I've liked Python: it's elegant and simple and still dynamic and
flexible. You could do worse for a clean and pragmatic language.
I do know my Smaltalk from my Common Lisp and my Ruby from my C#, so I
think I'm quite capable of escaping...
|
by: diffuser78 |
last post by:
I have just started to learn python. Some said that its slow. Can
somebody pin point the issue.
Thans
| |
by: abhinav |
last post by:
Hi guys.I have to implement a topical crawler as a part of my
project.What language should i implement
C or Python?Python though has fast development cycle but my concern is
speed also.I want to strke a balance between development speed and
crawler speed.Since Python is an interpreted language it is rather
slow.The crawler which will be working on huge set of pages should be
as fast as possible.One possible implementation would be...
|
by: 63q2o4i02 |
last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning
Python the past few months and like it very much. A few years ago I
had an AI class where we had to use Lisp, and I absolutely hated it,
having learned C++ a few years prior. They didn't teach Lisp at all
and instead expected us to learn on our own. I wasn't aware I had to
uproot my thought process to "get" it and wound up feeling like a
moron.
In learning Python I've...
|
by: Nicholas Reville |
last post by:
Hi, I hope this is an OK spot for this question:
I'm a co-founder of the Participatory Culture Foundation
(pculture.org), we're a non-profit that develops Democracy Player and
some related internet TV tools (see getdemocracy.com). Democracy
Player has a Python backend with native front-ends for Mac, Windows,
and Linux.
We're looking to expand our development team, but we haven't been
getting enough top-quality applicants. I was...
|
by: Vicent Giner |
last post by:
Hello.
I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.
However, it is usually said that Python is not a compiled but
interpreted programming language —I mean, it is not like C, in that
sense.
I am working on my PhD Thesis, which is about Operations Research,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |