Path: news.mathworks.com!not-for-mail
From: "Yair Altman" <altmanyDEL@gmailDEL.comDEL>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Can this run any faster?
Date: Thu, 11 Apr 2013 14:13:09 +0000 (UTC)
Organization: TACT Computer Systems Ltd
Lines: 29
Message-ID: <kk6gdl$8jp$1@newscl01ah.mathworks.com>
References: <kk24q4$3j5$1@newscl01ah.mathworks.com> <kk5unh$gc1$1@newscl01ah.mathworks.com>
Reply-To: "Yair Altman" <altmanyDEL@gmailDEL.comDEL>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1365689589 8825 172.30.248.48 (11 Apr 2013 14:13:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 11 Apr 2013 14:13:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642467
Xref: news.mathworks.com comp.soft-sys.matlab:793281

"Heinrich Acker" wrote in message <kk5unh$gc1$1@newscl01ah.mathworks.com>...
[snip]
> My experience is that using inf or nan can slow down calculations significantly. I didn't try your code, nor did I try it recently on one of my programs, but since that discovery I went back to the old practice to use an extremly large value instead of inf. It is not always possible, but in many algorithms you will know a finite value that is larger than all finite values that can appear in that place, e.g. 1e99. So the suggestion is to use this value as a metaphor for inf, even if this seems to be less refined.
> 
> Of course, the result depends on the architecture of the system you are using. It may not help on your system at all. Your disappointing result when mexing the function is an indicator of an inf or nan speed problem, though. When I came across it, I briefly googled the problem and found out that some architectures raise an execption to process inf or nan, instead of producing an IEEE754 result directly by the FPU.
> 
> Heinrich


I do not know which platform/ML release you are using Heinrich, but at least on Windows R2013a your statement seems to be incorrect. See below:

   >> tic, a=intmax; for idx=1:1e6; if (a==intmax) b=1; else, b=2; end, end, toc
   Elapsed time is 5.929147 seconds.

   >> tic, a=0; for idx=1:1e6; if (a==inf) b=1; else, b=2; end, end, toc
   Elapsed time is 0.013034 seconds.

   >> tic, a=inf; for idx=1:1e6; if (a==inf) b=1; else, b=2; end, end, toc
   Elapsed time is 0.013131 seconds.

   >> tic, a=0; for idx=1:1e6; if isinf(a) b=1; else, b=2; end, end, toc
   Elapsed time is 0.006696 seconds.

   >> tic, a=inf; for idx=1:1e6; if isinf(a) b=1; else, b=2; end, end, toc
   Elapsed time is 0.007951 seconds.

Yair Altman
http://UndocumentedMatlab.com