[Pyrex] Pyrex method 10x slower than Python, any hints why?
David Chiang
dwchiang at yahoo.com
Fri Jun 2 18:19:06 UTC 2006
Hi, I'm embarrassed to say that my problem was in relying on hotshot's reporting of total CPU time -- after paring things down, I found that the Pyrex version ran twice as fast (according to resource.getrusage's user+system time) but hotshot was reporting it as twice as slow!
So this is no longer a Pyrex issue (apologies), and maybe it's already a well-known issue with the profiler, but, for the curious, here is an example which displays the effect in a more pronounced way. The fact that C.m() is contained in a class and that it makes many calls to m.f() both appear to be necessary for it to happen.
main.py (measurement code omitted)
------------
import c1, c2
o1 = c1.C()
o2 = c2.C()
def f1():
o1.m()
def f2():
o2.m()
for j in xrange(2):
t = cpu()
for i in xrange(10000):
f1()
print ("python: %f s" % (cpu()-t))
t = cpu()
for i in xrange(10000):
f2()
print ("pyrex: %f s" % (cpu()-t))
c1.py = c2.pyx
----------------------
import m
class C:
def m(self):
for i in xrange(1000):
m.f()
m.pyx
-----------
def f():
pass
Output
----------
python: 32.786016 s
pyrex: 2.280653 s
python: 32.802013 s
pyrex: 2.275654 s
60010 function calls in 4.625 CPU seconds
Ordered by: internal time, call count
ncalls tottime percall cumtime percall filename:lineno(function)
20000 4.521 0.000 4.521 0.000 main.py:21(f2)
20000 0.072 0.000 0.104 0.000 main.py:18(f1)
20000 0.033 0.000 0.033 0.000 c1.py:4(f)
1 0.000 0.000 0.000 0.000 c1.py:1(?)
8 0.000 0.000 0.000 0.000 main.py:5(cpu)
1 0.000 0.000 0.000 0.000 c1.py:3(C)
0 0.000 0.000 profile:0(profiler)
David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.py
Type: text/x-python
Size: 703 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20060602/bf0db8ee/attachment.py
More information about the Pyrex
mailing list