help-octave
[Top][All Lists]
Advanced

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

Re: structure vs. vector


From: Paul Kienzle
Subject: Re: structure vs. vector
Date: Mon, 12 Feb 2001 00:44:45 +0000
User-agent: Mutt/1.2.5i

On Mon, Feb 12, 2001 at 03:53:32PM +0000, Etienne Grossmann wrote:
<snip>

> #  I've wrote an options processor a while back.  Maybe you are
> #  interested in it?  It allows the user to specify options as
> #  structures and to override the default options with a global
> #  structure in addition to the normal option processing.  Since it
> #  returns a structure, it is easy to pass all the options at once to
> #  your various subfunctions.  See attached.
> 
>   I will have a look at it this evening. The reason I used a vec for
> control parameters was to reduce overhead (e.g. if I have to
> optimize many easy-to-minimize functions, I'd rather not have many
> times the overhead).

Actually, structure references are faster:

octave2.1:4> t=time; for i=1:100, y.i=i; end; time-t, clear y
ans = 0.011328
octave2.1:5> t=time; for i=1:100, y=i; end; time-t, clear y
ans = 0.0092781
octave2.1:6> t=time; for i=1:100, y(1)=i; end; time-t, clear y
ans = 0.028970

You wouldn't believe the contortions octave goes through to assign a value
to an indexed vector!  I got some speedup by checking for scalar values
in octave_matrix::assign (in ov-re-mat.cc) but not enough to explain
the factor of 1000 between looping over a matrix in an octave script
and looping over a Matrix in liboctave.  The interpreter is adding a
factor of three.  So there is is a factor of three hundred in working
with octave_value's rather than Matrix's.  Some of that is looking up
operators every time through the loop.  Some of that is setting the
index.  Some of that is checking every time if you need to promote
or otherwise transform the type, but I don't remember how much for
each.

        - Paul


> 
>   Thanks for the feedback,
> 
>   Etienne
> 



-------------------------------------------------------------
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]