views:

122

answers:

1

I wrote some Python code and it worked fine when using the "python". I then converted it to C using "Cython" and used distutils to compile it to a shared library. I then changed some of the code to Cython so it would run faster. But when I imported the .so module and tried to use the command I had "cdef"ed it said that the command didn't exist. Original code:

import time as t
def time(function):
    t1 = t.time()
    function()
    t2 = t.time()
    return t2 - t1

New code:

import time as t
cdef time(function):
    t1 = t.time()
    function()
    t2 = t.time()
    return t2 - t1

I tried using "cdef int time" but I got the same result. Any advice?

+1  A: 

cdef functions are not exposed to Python. cpdef is provided to provide a Python wrapper to a C function defined in Cython.

Also, you're probably better off using timeit than bothering with implementing this.

Mike Graham
I knew there was better ways, but this was just an example.
None