Python speed vs csharp
Alexandre Fayolle
alf at fayauffre.org
Thu Jul 31 05:22:41 EDT 2003
Dans l'article <rkdc7poiachh.1x4jtxjzaf3zo.dlg at 40tude.net>, Mike a écrit :
> This is an error function approximation, which gets called around 1.5
> billion times during the simulation, and takes around 3500 seconds (just
> under an hour) to complete. While trying to speed things up, I created a
> simple test case with the code above and a main function to call it 10
> million times. The code takes roughly 210 seconds to run.
Hi there.
This is pure numerical computation, it is therefore a job for psyco
(http://psyco.sf.net/)
I've made a quick test, cut'n'pasted your code in a small python module,
added the following lines:
--------------------------8<----------------------
def run():
results = []
for i in xrange(10000000):
x = i/100. # apply erfc to a float
y = erfc(x)
if __name__ == '__main__':
run()
-------------------------8<-----------------------
at the end. So I'm basically calling erfc 1 million times, and not doing
much with the result. On my older machine (1.1GHz Celeron), this takes
13 seconds.
By adding the following 2 lines at the top of the script:
---8<-------
import psyco
psyco.full()
----8<------
I get down to under 4 seconds.
This is obviously not as good as you'd get with c#, but it's still a
great gain with not too much work, I think.
--
Alexandre Fayolle
LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Développement logiciel avancé - Intelligence Artificielle - Formations
More information about the Python-list
mailing list