Prev: Flight gear Simulink
Next: error saving figure
From: Rune Allnor on 9 Oct 2006 06:52 Steve Amphlett skrev: > <snip, many complicated solutions... > > Here's a simple C solution: > > #include <stdio.h> > int main(void) > { > char c; > while((c=getchar())!=EOF) putchar(c==','? '.' : c); > } > > Usage: > > a.out < filein > fileout <ironic mode> Steve, you live in the pre-neolithic era. Shell scripts, particularly, the useful ones, have been obsolete for 15 years now. Unless it's fully integrated with your electric tooth brush and can keep you fully informed in real time about the latest soccer events in inner Bolivia, a computer program of any type is no good. </ironic mode> And they call MSWin "progress"... Oh well. Rune
From: Steve Amphlett on 9 Oct 2006 09:41 Rune Allnor wrote: > > > > <ironic mode> > > Steve, you live in the pre-neolithic era. Shell scripts, > particularly, > the useful ones, have been obsolete for 15 years now. Unless it's > fully integrated with your electric tooth brush and can keep you > fully informed in real time about the latest soccer events in inner > Bolivia, a computer program of any type is no good. > > </ironic mode> > > And they call MSWin "progress"... Give me a small black xterm with tiny (fixed 6x10 font) characters in it any day. Half the windows on my screen are in foreign countries anyway. Hopefully I'll retire before 19th Jan 2038.
From: Rune Allnor on 9 Oct 2006 11:15 Steve Amphlett skrev: > Rune Allnor wrote: > > > > > > > > <ironic mode> > > > > Steve, you live in the pre-neolithic era. Shell scripts, > > particularly, > > the useful ones, have been obsolete for 15 years now. Unless it's > > fully integrated with your electric tooth brush and can keep you > > fully informed in real time about the latest soccer events in inner > > Bolivia, a computer program of any type is no good. > > > > </ironic mode> > > > > And they call MSWin "progress"... > > Give me a small black xterm with tiny (fixed 6x10 font) characters in > it any day. Half the windows on my screen are in foreign countries > anyway. Hopefully I'll retire before 19th Jan 2038. Yeah, right. Neverland, Captain Hook and all that... a real crocodile, that one. Rune
From: per isakson on 9 Oct 2006 14:02 Titus Edelhofer wrote: > > > Hi Rune, Michael, per, ... > what about memmapfile? It's simple and fast for this kind of > problem (here > for R2006b): > > function comma2point(filename) > file=memmapfile(filename,'writable',true); > comma=uint8(','); > point=uint8('.'); > file.Data((file.Data==comma)') = point; > delete(file) > > Timing: 20MB file in 0.7seconds > > Cheers, > Titus > Hi Titus, I tried to compare the speeds of the two plain Matlab constructs - memmapfile and fread/fwrite. memmapfile is faster but the difference isn't that big - same order of magnitude. However, the times I measure with tic/toc are a bit confusing. Could that have something to do with caching of the harddrive? I have a 3+ year old Dell Workstation with two cpus. Yes, one should definately be aware of memmapfile. In this case, howerver, I hessitate to overwrite my textfile with data. >> [ t, ct ] = comma2point( 1e5, 'd:\slask\point.txt', 'd:\slask\comma.txt') fread memmapfile tic&toc = 1.6002 1.5717 cpuTime = 0.6563 0.1563 >> [ t, ct ] = comma2point( 1.25e5, 'd:\slask\point.txt', 'd:\slask\comma.txt') t = 2.9311 0.5472 ct = 0.8594 0.2031 >> function [ t, ct ] = comma2point( sz, strInFileSpec, strOutFileSpec ) M = rand( sz, 10 ); save( strInFileSpec, 'M', '-ascii' ), tic, ct0 = cputime; fread_( strInFileSpec, strOutFileSpec ), t = toc; ct = cputime - ct0; tic, ct0 = cputime; memmap_( strOutFileSpec ), t(2) = toc; ct(2) = cputime - ct0; end function fread_( strInFileSpec, strOutFileSpec ) fid = fopen( strInFileSpec, 'r' ); str = fread( fid, inf, '*char' ); fclose( fid ); str = strrep( str', '.', ',' ); fid = fopen( strOutFileSpec, 'w' ); fwrite( fid, str, 'char' ); fclose( fid ); end function memmap_( strOutFileSpec ) file = memmapfile( strInFileSpec, 'writable', true ); comma=uint8(','); point=uint8('.'); file.Data(( file.Data==comma)' ) = point; delete(file) end Cheers, per
From: Titus Edelhofer on 10 Oct 2006 06:36
Hi Per, I admit, I was confused for some seconds as well, but I think I know now what's happening: you are measuring two different things: - tic/toc measures the elapsed (real-)time, i.e., the time in seconds between tic and toc (regardless of how much the computer actually does!) - cputime is the time MATLAB has bothered the cpu with load function cputime_vs_tictoc tic ct0=cputime; pause(2); t=toc ct1=cputime-ct0 leads to (on mymachine) t = 1.993 ct1 = 0.0100 so, as you already guessed: for the call to fread/fwrite MATLAB (CPU) waits for data from the harddisk, whereas the second is probably in the windows file system cache Titus "per isakson" <poi1(a)kth2.se> schrieb im Newsbeitrag news:ef42e6a.13(a)webcrossing.raydaftYaTP... > Titus Edelhofer wrote: >> >> >> Hi Rune, Michael, per, ... >> what about memmapfile? It's simple and fast for this kind of >> problem (here >> for R2006b): >> >> function comma2point(filename) >> file=memmapfile(filename,'writable',true); >> comma=uint8(','); >> point=uint8('.'); >> file.Data((file.Data==comma)') = point; >> delete(file) >> >> Timing: 20MB file in 0.7seconds >> >> Cheers, >> Titus >> > > Hi Titus, > > I tried to compare the speeds of the two plain Matlab constructs - > memmapfile and fread/fwrite. memmapfile is faster but the difference > isn't that big - same order of magnitude. However, the times I > measure with tic/toc are a bit confusing. Could that have something > to do with caching of the harddrive? I have a 3+ year old Dell > Workstation with two cpus. > > Yes, one should definately be aware of memmapfile. In this case, > howerver, I hessitate to overwrite my textfile with data. > >>> [ t, ct ] = comma2point( 1e5, 'd:\slask\point.txt', > 'd:\slask\comma.txt') > > fread memmapfile > tic&toc = 1.6002 1.5717 > cpuTime = 0.6563 0.1563 > >>> [ t, ct ] = comma2point( 1.25e5, 'd:\slask\point.txt', > 'd:\slask\comma.txt') > t = > 2.9311 0.5472 > ct = > 0.8594 0.2031 >>> > > function [ t, ct ] = comma2point( sz, strInFileSpec, strOutFileSpec > ) > > M = rand( sz, 10 ); > save( strInFileSpec, 'M', '-ascii' ), > > tic, ct0 = cputime; > fread_( strInFileSpec, strOutFileSpec ), > t = toc; ct = cputime - ct0; > > tic, ct0 = cputime; > memmap_( strOutFileSpec ), > t(2) = toc; ct(2) = cputime - ct0; > > end > > function fread_( strInFileSpec, strOutFileSpec ) > > fid = fopen( strInFileSpec, 'r' ); > str = fread( fid, inf, '*char' ); > fclose( fid ); > > str = strrep( str', '.', ',' ); > > fid = fopen( strOutFileSpec, 'w' ); > fwrite( fid, str, 'char' ); > fclose( fid ); > > end > > function memmap_( strOutFileSpec ) > > file = memmapfile( strInFileSpec, 'writable', true ); > comma=uint8(','); > point=uint8('.'); > file.Data(( file.Data==comma)' ) = point; > delete(file) > > end > > Cheers, > per |