[SciPy-user] random number sampling performance in newcore

Robert Kern rkern at ucsd.edu
Fri Nov 11 03:15:20 CST 2005


Chris Fonnesbeck wrote:

> My tests were pretty simple and informal -- just 100K identically
> distributed samples:
> 
> In [1]: from scipy import random as rnums
> 
> In [2]: from time import time
> 
> In [3]: import RandomArray as ra
> 
> In [4]: start=time();foo=ra.binomial(100,0.3,100000);print time()-start
> 0.21244597435
> 
> In [5]: start=time();foo=rnums.binomial(100,0.3,100000);print time()-start
> 1.73217105865

It turns out the algorithm I was using for the small-mean case wasn't
the greatest. This is fixed, now.

> Its also faster in RandomArray for gamma, but not as dramatic:
> 
> In [7]: start=time();foo=rnums.gamma(3,5,1000000);print time()-start
> 0.938844919205
> 
> In [8]: start=time();foo=ra.gamma(3,5,1000000);print time()-start
> 0.690024852753

On my computer, it's even less dramatic.

In [15]: Timer('x=RA.gamma(3,1.0,1000000)', 'import RandomArray as
RA').repeat(3,10)
Out[15]: [12.582072019577026, 12.48114800453186, 12.486257076263428]

In [16]: Timer('x=random.gamma(3,size=1000000)', 'from scipy import
random').repeat(3,10)
Out[16]: [14.418467044830322, 14.438578128814697, 14.841632127761841]

RANLIB does use a somewhat more state-of-the-art generator for gamma
than I do, but one that is also longer and rather more complicated. I
happen to count those criteria at least as important as speed
(especially as I'm the one doing the implementing, here).

If you see any more glaring performance problems, let me know, and I'll
investigate them.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter



More information about the SciPy-user mailing list