News for hackers. Stuff that matters.
Re:Pre-Allocated Lists in Python by w-m on Wednesday March 30, 2022 @09:15AM (#30854777)
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)

There are no comments on this comment yet.