3 ms·
Here was a weird one for me, why is numba jitted initialization twice as fast as np.arange, which presumably has a C implementation? In [1]: import numpy as
by w-m 5y ago
Here was a weird one for me, why is numba jitted initialization twice as fast as np.arange, which presumably has a C implementation?
In [1]: import numpy as np
In [2]: %timeit np.arange(10000, dtype=np.int64)
3.03 µs ± 94.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
In [3]: import numba
In [4]: @numba.jit
...: def alloc_np_jit(length):
...: pre = np.empty(length, dtype=np.int64)
...: for i in range(length):
...: pre[i] = i
...: return pre
...:
In [5]: %timeit alloc_np_jit(10000)
1.56 µs ± 12.7 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)