Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!a32g2000yqm.googlegroups.com!not-for-mail
From: roger <northsolomonsea@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: matlab typecast function very slow
Date: Tue, 3 Nov 2009 06:54:32 -0800 (PST)
Organization: http://groups.google.com
Lines: 31
Message-ID: <0598df9f-fdca-4bb3-bbb0-22b6ff33331c@a32g2000yqm.googlegroups.com>
References: <05e24510-1633-4d87-9cbb-39230a6efeec@n35g2000yqm.googlegroups.com> 
	<hcpehq$ct7$1@fred.mathworks.com>
NNTP-Posting-Host: 195.193.213.214
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1257260072 32494 127.0.0.1 (3 Nov 2009 14:54:32 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 3 Nov 2009 14:54:32 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: a32g2000yqm.googlegroups.com; posting-host=195.193.213.214; 
	posting-account=BbKioQoAAAAt_SMfLTBT5PYUV9nQycia
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 
	InfoPath.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.648; 
	.NET CLR 3.5.21022),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:582058


On Nov 3, 3:26 pm, "James Tursa"
<aclassyguy_with_a_k_not_...@hotmail.com> wrote:
> roger <northsolomon...@gmail.com> wrote in message <05e24510-1633-4d87-9cbb-39230a6ef...@n35g2000yqm.googlegroups.com>...
>
> > Since the function isn't too fast I thought I'd read the entire file
> > at once as uint8 and then typecast byte by byte to the relevant
> > datatypes.
>
> > To my surprise the typecast method is actually a _lot_ slower than
> > consecutively using fread, on inspection the profiler shows that the
> > typecast function is the main culprit.
>
> If you want a fast typecast function, use my FEX submission that can be found here:
>
> http://www.mathworks.com/matlabcentral/fileexchange/17476-typecast-c-...
>
> The MATLAB built-in typecast does a data copy to generate the result. My version of typecast does not do a data copy, but does a shared data copy, so it runs faster. The speed improvement will depend on the size of the data. My files are names typecast.m and typecast.c, but you could rename them to something else if desired.
>
> James Tursa

James,
Many thanks, although I'll probably write the whole reading/converting
part in C++ and transfer the lot back to matlab via mx the shared data
copy is very interesting!
regards, R