[Numpy-discussion] python's random.random() faster than numpy.random.rand() ???
Stefan van der Walt
stefan at sun.ac.za
Sat Jan 27 17:17:00 EST 2007
Hi Mark
On Fri, Jan 26, 2007 at 10:17:58AM -0700, Mark P. Miller wrote:
> I've recently been working with numpy's random number generators and
> noticed that python's core random number generator is faster than
> numpy's for the uniform distribution.
>
> In other words,
>
> for a in range(1000000):
> b = random.random() #core python code
>
> is substantially faster than
>
> for a in range(1000000):
> b = numpy.random.rand() #numpy code
With numpy, you can get around the for-loop by doing
N.random.random(1000000)
which is much faster:
In [7]: timeit for i in range(10000): random.random()
100 loops, best of 3: 3.92 ms per loop
In [8]: timeit N.random.random(10000)
1000 loops, best of 3: 514 µs per loop
Cheers
Stéfan
More information about the NumPy-Discussion
mailing list