Path: news.mathworks.com!not-for-mail
From: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matlab Vectorisation Speed - How is it done in c++?
Date: Mon, 17 Dec 2007 13:55:30 +0000 (UTC)
Organization: Ricardo UK Ltd
Lines: 26
Message-ID: <fk5v4i$4su$1@fred.mathworks.com>
References: <eb177713-6655-4454-bbf6-92d2c91bb6a6@s19g2000prg.googlegroups.com>
Reply-To: "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1197899730 5022 172.30.248.35 (17 Dec 2007 13:55:30 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 17 Dec 2007 13:55:30 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 43398
Xref: news.mathworks.com comp.soft-sys.matlab:442742



Phil Winder <philipwinder@googlemail.com> wrote in message 
<eb177713-6655-4454-bbf6-
92d2c91bb6a6@s19g2000prg.googlegroups.com>...
> Hi,
> Im currently porting some matlab algorithms to c++ code.  
The test
> code I have is testing the vector math capabilities and 
how fast they
> can go.  I have found that it can be very, very fast and 
I am
> strugglling to reproduce the speed in c++. How does 
matlab do it? And
> how can it be reproduced in c++?
> 
> Thanks,
> Phil Winder

If you can work "in place" you'll get a 10+ speedup:

>> myfunc(x);

rather than

x=myfunc(x);

All that memory allocation and copying is a waste.