[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: efficiency
From: |
Daniel Heiserer |
Subject: |
Re: efficiency |
Date: |
Tue, 01 Feb 2000 08:40:30 +0100 |
address@hidden wrote:
>
> Hello,
>
> # Assume I have a few hundred matrices:
> # k_0004711
> # k_0004712
> # .........
> # And I want to loop through a subset of them
> # with a certain function:
> # like:
>
> # a=myfunc(b,c,K__00047[1-5]) # in shell regexps .... ;-)
> # call for each matrix
>
> # What is better/more efficient:
>
> # 1) copying the data via a temporary variable
> # for jj=1:5
> # tmp=eval(sprintf('k_%7d',47*1000+jj));
> # a=myfunc(b,c,tmp);
> # end
> # % Which probably means copying data in core each time .......
> # % for big loops not nice .......
> # or
>
> What about
>
> jj=1:5;
> eval(sprintf("a = myfunc(b,c,k_%7d);",47*1000+jj)) ;
>
> ? There is a single eval, and not much code around it. Timing seems
> improved, at least in the simplified case below :
>
> octave:7> mytic(); eval(sprintf("k%04d=eye(3);",0:1000)) ; mytic()
Wow. I didn't think of this.
VERY nice ;-) An implicit loop. Cool.
is the mytic your private routine? I dont have it.
> ans = 0.29000
> octave:8> mytic(); for i=1:1000, eval(sprintf("k%04d=eye(3);",i)) ; end ;
> mytic()
> ans = 0.66000
>
> where mytic() returns the time since last call to mytic().
>
> # 3) put all the crap in ONE Monster array, store the indices somewhere
> # and do it like this and making all the code realy ugly .......
>
> # a=myfunc(a,b,K_monster,K_indices);
> # % is here any data copied?
> # % and does it only make the code unreadible
>
Thanks Daniel
-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.che.wisc.edu/octave/octave.html
How to fund new projects: http://www.che.wisc.edu/octave/funding.html
Subscription information: http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------
- Re: efficiency,
Daniel Heiserer <=