Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!nx01.iad01.newshosting.com!newshosting.com!69.28.186.77.MISMATCH!hwmpeer03.lga!news.highwinds-media.com!llnews!53ab2750!not-for-mail
From: Peter Boettcher <boettcher@ll.mit.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: eval, feval, global
References: <fsebf0$43u$1@fred.mathworks.com>
Message-ID: <muyprtgjjom.fsf@G99-Boettcher.llan.ll.mit.edu>
Organization: MIT Lincoln Laboratory
User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/23.0.0 (gnu/linux)
Cancel-Lock: sha1:f2NBQO+8ZHCjfNhNNLwbcoMwS7M=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 37
Date: Thu, 27 Mar 2008 11:00:41 -0400
NNTP-Posting-Host: 155.34.163.114
X-Complaints-To: news@ll.mit.edu
X-Trace: llnews 1206629455 155.34.163.114 (Thu, 27 Mar 2008 10:50:55 EDT)
NNTP-Posting-Date: Thu, 27 Mar 2008 10:50:55 EDT
Xref: news.mathworks.com comp.soft-sys.matlab:459487


"Yuri Geshelin" <geshelin@hotmail.com> writes:

> Many thanks to everyone who replied.
>
> The fastest algorithm is Phil's. Assuming that its time is 
> unity, here is the cpu time summary of the following test 
> case:
>
> t = cputime; <code_name>(1:10,1000001:1000010); <code_time> 
> = cputime-t;
>
> -------------------------------------
>
> Phil's construct_array4.m - 1.00
> My awkward EVAL implementation (construct_array.m) - 1.67
> mmrepeat - 3.40
> Sven's code - 3.47
> My original version (no preallocation) - 4.00
>
> ------------------------------------
>
> You convinced me that EVAL is beatable.

That said, sometimes you have work to do, and a solution with eval leaps
to mind.  Great.  Use it and get on with life.  Maybe that solution
takes less time to write/maintain than some other fancier vectorizing
thing.  In your case, I would suggest leaving your simple loop in place
in a comment to illustrate what is happening, with a note that the eval
version is inexplicably faster.

In 98% of the cases we see here, the use of eval is due to a failure to
understand arrays, the difference between literal strings and string
variables, etc.  These cases are easily correctable, and the switch away
from eval leads to code which is better by any and all metrics.


-Peter