Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!c37g2000yqi.googlegroups.com!not-for-mail
From: Dan <dnp037@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Minor disappointment with Matlab
Date: Fri, 4 Sep 2009 15:00:57 -0700 (PDT)
Organization: http://groups.google.com
Lines: 32
Message-ID: <25f0b0e8-fa6b-4283-81eb-d3bfebeb4a97@c37g2000yqi.googlegroups.com>
NNTP-Posting-Host: 199.46.240.168
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1252101657 11234 127.0.0.1 (4 Sep 2009 22:00:57 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Fri, 4 Sep 2009 22:00:57 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: c37g2000yqi.googlegroups.com; posting-host=199.46.240.168; 
	posting-account=A4bkYwkAAACb_Gvc_qdps_d-fzN6tydb
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET 
	CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:568478


The other day, because some of my simulation code was taking a long
time to run, I spent some time trying to optimize the algorithm. This
was wasted time, because when I finally got around to profiling the
code, it seems that most of the time was spent in the Matlab "cross"
function. I thought this was such a basic function that I did not look
there for my problem. When I replaced the built-in function with my
own, the simulation was sped up by about a factor of 30.

Here is some representative code to illustrate:

(execution times and percentages from "profile" on the right)

for k=1:100000
    a = rand
(1,3);    ..............................................................................
0.265s    2.7%
    b = rand
(1,3);    ..............................................................................
0.125s    1.3%
    c = cross
(a,b);  ..............................................................................
9.340s   94.2%
    d = [ a(2)*b(3)-a(3)*b(2), a(3)*b(1)-a(1)*b(3), a(1)*b(2)-a(2)*b
(1) ]; .........    0.172s    1.7% (same as "cross")
end


I recommend that you carefully consider using "cross" in calculation
intensive code.

Regards,
Dan