[SciPy-user] random number sampling performance in newcore
fonnesbeck at gmail.com
Wed Nov 9 08:11:28 CST 2005
On 11/8/05, Robert Kern <rkern at ucsd.edu> wrote:
> Chris Fonnesbeck wrote:
> > I was surprised to find that the random number sampler in newcore is
> > significantly slower than RandomArray in Numeric (at least for
> > binomial sampling). A quick comparison showed the
> > scipy.basic.random.binomial sampler to be over 8 times slower than
> > RandomArray.binomial. I was surprised, since the newcore stuff is
> > Pyrex-based (isnt it?).
> It's a Pyrex wrapper to pure C code. See distributions.c for the actual
> implementations of the distribution algorithms.
> > Am I the only one observing such differences,
> > or am I using the wrong method? If not, is the performance expected to
> > improve significantly.
> Can you show us the code you're using? Particularly, the parameters p
> and n. I use two different algorithms for the binomial distribution, a
> waiting time algorithm when p*n <= 30 (or (1-p)*n <= 30 if p > 0.5) and
> the BTPE algorithm (the same algorithm that's in RANLIB, but
> reimplemented) when p*n > 30 (or (1-p)*n ...).
My tests were pretty simple and informal -- just 100K identically
In : from scipy import random as rnums
In : from time import time
In : import RandomArray as ra
In : start=time();foo=ra.binomial(100,0.3,100000);print time()-start
In : start=time();foo=rnums.binomial(100,0.3,100000);print time()-start
Its also faster in RandomArray for gamma, but not as dramatic:
In : start=time();foo=rnums.gamma(3,5,1000000);print time()-start
In : start=time();foo=ra.gamma(3,5,1000000);print time()-start
More information about the SciPy-user