4 ms·
Am I missing something? With numpy on my 2017 Macbook Pro, I can generate 1B random, normally distributed numbers on a CPU in ~1.3 microseconds. In [3]: %timei
by thisguy47 7y ago
Am I missing something? With numpy on my 2017 Macbook Pro, I can generate 1B random, normally distributed numbers on a CPU in ~1.3 microseconds.
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)
- zaarn 7y agoI don't think that is measured correctly: A CPU at 5GHz would take 0.2ns per cycle, how is it supposed to generate 1 billion (!) numbers in only 100x the time? Even if you had 64c/128t threadrippers in a dualsocket and this workload perfectly distributed, you'd only get within 100'000x the time of a single cycle. There's still a factor of 10'000 left. 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.
- nimih 7y agoYou might be misremembering the numpy.random api, since you appear to only be generating one or two random numbers in your tests. 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.
- thisguy47 7y agoAh yes, thanks everyone for pointing out my mistake, I am not using the `size` parameter, so this is really only generating a single random number. My mistake!