
Anders Hammarquist wrote:
Anyway, what I was thinking about, and need input on, is how to get at the interpreters to run the benchmark. [...]
I wonder, would it be possible to add Cython to the benchmark loop? I would love to see it compared to PyPy, simply because both projects aim to compile Python code to C code (amongst other things, obviously). I know that Cython can't currently compete with PyPy in terms of feature completeness - it clearly lacks some very important features of the Python language, so it won't be able to run all benchmarks for a while, and the comparison would easily show where the black spots are that need fixing. Just out of curiosity (and to wet your appetite :), I ran PyPy's richards benchmark unmodified in Cython (latest cython-unstable) and got this: python2.6 -c 'import richards; richards.main()' Richards benchmark (Python) starting... [...] finished. Total time for 10 iterations: 3.98 secs Average time per iteration: 398.44 ms compared to CPython 2.6.2: python2.6 -c 'import richards; richards.main()' Richards benchmark (Python) starting... [...] finished. Total time for 10 iterations: 4.86 secs Average time per iteration: 485.97 ms That's almost 20% faster IMO and not bad at all, given that Cython's main performance feature (C typing) wasn't used. When I use an external .pxd file (attached) to redeclare the classes as extension types and to add a C nature to their methods (still without any benchmark code modifications), I get this: python2.6 -c 'import richards; richards.main(iterations=10)' Richards benchmark (Python) starting... [...] finished. Total time for 10 iterations: 0.99 secs Average time per iteration: 99.28 ms That's almost a factor of five compared to CPython. If possible, I would like to add both a normal Cython compiler run and a pxd enabled run to the benchmark comparison with PyPy and CPython. Any chance this could be integrated? I'm asking now, because I imagine that the benchmarking framework will have to integrate the Cython compiler somehow, maybe using distutils or on-the-fly compilation with pyximport. Stefan cimport cython cdef class Packet: cdef public object link cdef public object ident cdef public object kind cdef public object datum cdef public object data cpdef append_to(self,lst) cdef class TaskRec: pass cdef class DeviceTaskRec(TaskRec): cdef public object pending cdef class IdleTaskRec(TaskRec): cdef public object control cdef public Py_ssize_t count cdef class HandlerTaskRec(TaskRec): cdef public object work_in # = None cdef public object device_in # = None cpdef workInAdd(self,p) cpdef deviceInAdd(self,p) cdef class WorkerTaskRec(TaskRec): cdef public object destination # = I_HANDLERA cdef public Py_ssize_t count cdef class TaskState: cdef public bool packet_pending # = True cdef public bool task_waiting # = False cdef public bool task_holding # = False cpdef packetPending(self) cpdef waiting(self) cpdef running(self) cpdef waitingWithPacket(self) cpdef isPacketPending(self) cpdef isTaskWaiting(self) cpdef isTaskHolding(self) cpdef isTaskHoldingOrWaiting(self) cpdef isWaitingWithPacket(self) cdef class TaskWorkArea: cdef public list taskTab # = [None] * TASKTABSIZE cdef public object taskList # = None cdef public Py_ssize_t holdCount # = 0 cdef public Py_ssize_t qpktCount # = 0 cdef class Task(TaskState): cdef public Task link # = taskWorkArea.taskList cdef public object ident # = i cdef public object priority # = p cdef public object input # = w cdef public object handle # = r cpdef addPacket(self,Packet p,old) cpdef runTask(self) cpdef waitTask(self) cpdef hold(self) cpdef release(self,i) cpdef qpkt(self,Packet pkt) cpdef findtcb(self,id) cdef class DeviceTask(Task): @cython.locals(d=DeviceTaskRec) cpdef fn(self,pkt,r) cdef class HandlerTask(Task): @cython.locals(h=HandlerTaskRec) cpdef fn(self,pkt,r) cdef class IdleTask(Task): @cython.locals(i=IdleTaskRec) cpdef fn(self,pkt,r) cdef class WorkTask(Task): @cython.locals(w=WorkerTaskRec) cpdef fn(self,pkt,r) @cython.locals(t=Task) cpdef schedule() cdef class Richards: cpdef run(self, iterations)