Open in CoCalc with one click!
In [1]:
import sys sys.version
'3.5.2 (default, Nov 23 2017, 16:37:01) \n[GCC 5.4.0 20160609]'
In [2]:
import numba
In [3]:
from numba import jit, int64
In [4]:
def f1(x, y): o = 0 for i in range(x): for j in range(i, y, 2): if (i + j) % 13 != 0: o += i - j return o
In [5]:
f1(1000, 1000)
-76923768
In [6]:
%timeit f1(1000, 1000)
67 ms ± 5.65 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [7]:
@jit(int64(int64, int64), nopython=False) def f2(x, y): o = 0 for i in range(x): for j in range(i, y, 2): if (i + j) % 13 != 0: o += i - j return o
In [8]:
f2(1000, 1000)
-76923768
In [9]:
%timeit f2(1000, 1000)
728 µs ± 57.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [ ]:
In [ ]: