Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
In [1]: import numpy as np
In [2]: np.__version__
Out[2]: '1.19.5'
In [3]: a = np.arange(1e6)
In [4]: %timeit x = np.array(a).copy()
1.12 ms ± 10.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [5]: %timeit x = np.ascontiguousarray(a).copy()
527 µs ± 3.63 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [6]: %timeit x = np.array([0,1,2]).copy()
1.48 µs ± 6.99 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [7]: %timeit x = np.ascontiguousarray([0,1,2]).copy()
2.31 µs ± 29.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
In [1]: import numpy as np
In [2]: np.__version__
Out[2]: '1.20.1'
In [3]: a = np.arange(1e6)
In [4]: %timeit x = np.array(a).copy()
1.06 ms ± 22.1 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [5]: %timeit x = np.ascontiguousarray(a).copy()
521 µs ± 4.37 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [6]: %timeit x = np.array([0,1,2]).copy()
976 ns ± 12.9 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [7]: %timeit x = np.ascontiguousarray([0,1,2]).copy()
1.59 µs ± 23.4 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment