In the interest of fixing

http://trac.cython.org/cython_trac/ticket/281

I'm doing some benchmarks which are rather surprising to me. 
Explanations? Unless something is wrong it seems I can safely replace 
__pyx_lineno and friends with thread variables (on Python versions which 
support it, haven't checked that yet).

In [12]: %timeit dagss.globalvar(1e3)
100 loops, best of 3: 6.18 ms per loop

In [13]: %timeit dagss.threadvar(1e3)
10000 loops, best of 3: 553 micros per loop

In [14]: %timeit dagss.threadvar(1e6)
10 loops, best of 3: 153 ms per loop

cdef extern from "pythread.h":
     int PyThread_create_key()
     void PyThread_delete_key(int)
     int PyThread_set_key_value(int, void *)
     void* PyThread_get_key_value(int)
     void PyThread_delete_key_value(int key)

cdef int v

cdef void setvar(int x):
     global v
     v = x

cdef int getvar():
     return v

def threadvar(N):
     cdef int key = PyThread_create_key()
     cdef int i
     cdef void* j
     for i in range(N):
         PyThread_set_key_value(key, <void*>i)
         j = PyThread_get_key_value(key)

def globalvar(N):
     cdef int i
     cdef int j
     for i in range(N):
         setvar(i)
         j = getvar()




-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to