You are measuring two things together: allocation and an initialization inside a loop.
I would try to separate them (I.e. measure [None]*length and np.empty(length)
I would try to separate them (I.e. measure [None]*length and np.empty(length)
In [1]: length = 10_000
In [2]: %%timeit
...: pre = [None] * length
...:
...:
38.7 µs ± 128 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
In [3]: %%timeit
...: pre = np.empty(length, dtype=int)
...:
...:
1.32 µs ± 6.59 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)