logo       

Re: Pyrex method 10x slower than Python, any hints why?: msg#00008

python.pyrex

Subject: Re: Pyrex method 10x slower than Python, any hints why?

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


Attachment: main.py
Description: Text Data

_______________________________________________
Pyrex mailing list
Pyrex@xxxxxxxxxxxxxxxxx
http://lists.copyleft.no/mailman/listinfo/pyrex
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise