Commit 957f6b44 authored by Stefan Behnel's avatar Stefan Behnel

extend line profiling test to cover cpdef functions and methods

parent 7a518b87
...@@ -47,6 +47,12 @@ profile = line_profiler.LineProfiler(func) ...@@ -47,6 +47,12 @@ profile = line_profiler.LineProfiler(func)
profile.runcall(func, 19) profile.runcall(func, 19)
assert_stats(profile, func.__name__) assert_stats(profile, func.__name__)
from collatz import cp_collatz
func = cp_collatz
profile = line_profiler.LineProfiler(func)
profile.runcall(func, 19)
assert_stats(profile, func.__name__)
from collatz import PyClass from collatz import PyClass
obj = PyClass() obj = PyClass()
func = obj.py_pymethod func = obj.py_pymethod
...@@ -57,13 +63,15 @@ assert_stats(profile, func.__name__) ...@@ -57,13 +63,15 @@ assert_stats(profile, func.__name__)
from collatz import CClass from collatz import CClass
obj = CClass() obj = CClass()
func = obj.c_pymethod func = obj.c_pymethod
print(func)
print(type(func))
print(func.__func__)
profile = line_profiler.LineProfiler(func) profile = line_profiler.LineProfiler(func)
profile.runcall(func) profile.runcall(func)
assert_stats(profile, func.__name__) assert_stats(profile, func.__name__)
func = obj.cp_pymethod
profile = line_profiler.LineProfiler(func)
profile.runcall(func, 19)
assert_stats(profile, func.__name__)
######## collatz.pyx ########### ######## collatz.pyx ###########
# cython: binding=True # cython: binding=True
...@@ -76,6 +84,14 @@ def collatz(n): ...@@ -76,6 +84,14 @@ def collatz(n):
n = 3*n+1 n = 3*n+1
cpdef cp_collatz(n):
while n > 1:
if n % 2 == 0:
n //= 2
else:
n = 3*n+1
class PyClass(object): class PyClass(object):
def py_pymethod(self): def py_pymethod(self):
x = 1 x = 1
...@@ -91,6 +107,12 @@ cdef class CClass: ...@@ -91,6 +107,12 @@ cdef class CClass:
y = self.cmethod(c + a) y = self.cmethod(c + a)
return y * 4 return y * 4
cpdef cp_pymethod(self, r):
for i in range(10):
a = r + 1
z = self.c_pymethod(a) + self.cmethod(r)
return z * 2
cdef cmethod(self, s): cdef cmethod(self, s):
for i in range(10): for i in range(10):
p = s + 3 p = s + 3
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment