by thisguy47 · 7y ago · 0 comments
In [3]: %timeit np.random.normal(1000000000)
1.3 µs ± 26.2 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
Edit: and 2.5e17 in ~7.95 microseconds
In [5]: %timeit np.random.normal((500000000, 500000000))
7.95 µs ± 90.7 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
I get results about 100x slower those of the article's CPU benchmark when using numpy on a 2019 MBP:
python -m timeit -s 'import numpy as np; x = np.zeros(1000000)' -u msec 'np.random.normal(x)'
10 loops, best of 5: 30.9 msec per loop
edit: I'm no python wizard myself, so I'm perfectly willing to believe that there's a better way to generate a random array in numpy than what I'm doing.You might want to try this one:
np.random.normal(size=1000000000)
For size=1000 I get on my machine about 36 ns per number (total 36 µsecs). You probably measured for size=1 but a normal of 1 billion, not 1 billion numbers at a normal of 1.