In [1]:
from util import perf_comp_data

In [2]:
def fib(n):
    if n < 2:
        return n
    return fib(n - 1) + fib(n - 2)

assert fib(20) == 6765

In [3]:
from hope import jit

hope_fib = jit(fib)

assert hope_fib(20) == 6765

In [4]:
from numba import jit

numba_fib = jit(fib)
assert numba_fib(20) == 6765

In [5]:
print "python"
%timeit fib(20)
print "hope 1"
%timeit hope_fib(20)
print "numba"
%timeit numba_fib(20)


python
100 loops, best of 3: 2.59 ms per loop
hope 1
10000 loops, best of 3: 42 µs per loop
numba
100 loops, best of 3: 2.67 ms per loop

In [6]:
n=20
perf_comp_data(["fib", "hope_fib", "numba_fib"], 3*["n"])


function: hope_fib                      , av. time sec:   0.00005205, relative:       1.0
function: fib                           , av. time sec:   0.00290926, relative:      55.9
function: numba_fib                     , av. time sec:   0.00306726, relative:      58.9

In [7]:
numba_fib.inspect_types()


fib (int64,)
--------------------------------------------------------------------------------
# File: <ipython-input-2-24febe657cfb>
# --- LINE 1 --- 

def fib(n):

    # --- LINE 2 --- 
    # label 0
    #   n.1 = n  :: pyobject
    #   $const0.2 = const(<type 'int'>, 2)  :: pyobject
    #   $0.3 = n.1 < $const0.2  :: pyobject
    #   branch $0.3, 12, 16

    if n < 2:

        # --- LINE 3 --- 
        # label 12
        #   return n.1

        return n

    # --- LINE 4 --- 
    # label 16
    #   $16.1 = global(fib: <function fib at 0x10e6e9cf8>)  :: pyobject
    #   $const16.3 = const(<type 'int'>, 1)  :: pyobject
    #   $16.4 = n.1 - $const16.3  :: pyobject
    #   $16.5 = call $16.1($16.4, )  :: pyobject
    #   $16.6 = global(fib: <function fib at 0x10e6e9cf8>)  :: pyobject
    #   $const16.8 = const(<type 'int'>, 2)  :: pyobject
    #   $16.9 = n.1 - $const16.8  :: pyobject
    #   $16.10 = call $16.6($16.9, )  :: pyobject
    #   $16.11 = $16.5 + $16.10  :: pyobject
    #   return $16.11

    return fib(n - 1) + fib(n - 2)


================================================================================

In [ ]: