NotesOnCython
NotesOnCython copied to clipboard
Some notes on using Cython to increase the performance of Python code.
typed cpdef has same speed as cdef function NOTE: time in table is completely random number
def fib_cached(n, cache={}): if n < 2: return n try: val = cache[n] except KeyError: val = fib(n-2) + fib(n-1) cache[n] = val return val Maybe there is a typo...
Quick fix
There are lots of ways to write Cython. I normally suggest writing the optimised function with a pure C interface, declared "nogil". The nogil declaration tells the Cython compiler there...
This PR updates the notes to include benchmarks for using a typed cpdef function for the Fibonacci function (recursive algorithm). in more details: - All typed functions now return `long`...