help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: octave_rand::scalar() v. randn


From: Quentin Spencer
Subject: Re: octave_rand::scalar() v. randn
Date: Tue, 22 Feb 2005 20:56:33 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041127)

Steve C. Thompson wrote:

Group,

I've ask about this yesterday, but I will simplify the question.

Say you write a C++ program using the Octave headers (then make it into
an .oct module) which returns a vector of 1e7 Gaussian distributed
numbers.  Comparing the speed of this to randn(1,1e7), I've found randn
to be much much faster than calling octave_rand::scalar() many times.
I noticed in your original post that you used a floating point value to count to 1e7. I'm sure this won't change things too much, but an integer comparison will always be faster than a floating point one.

I will be adding more to this later.  I've converted a simple simulation
into C++, made the .oct file, and compared the performance to a
vectorized m-file-only simulation.  The pure m-file simulation runs
faster!  Try to explain that.
One of octave's bottlenecks is the parser, but a short m-file that just calls randn with a large size doesn't require much parsing, and makes one function call to generate the random numbers. Your C file calls a the random number generator 1e7 times, with all of the overhead that such a function call generates.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]