function [ sz1, sz_mat1, sz_mat2, sz_y ] = cssm
testFile = matfile('simData1','Writable',true);
testFile.y1 = [];
filePtr = 1;
sz1 = nan( 100, 1 );
for itr = 1:100
data = randn(1000,1);
testFile.y1(filePtr:filePtr+1000-1,1) = data;
filePtr = filePtr + 1000;
sad = dir('simData1.mat');
sz1(itr) = sad.bytes;
end
data = randn(1e5,1);
testFile2 = matfile('simData2','Writable',true);
testFile2.y2 = data;
[ sz_mat1, sz_mat2, sz_y ] = cssm_();
end
function [ sz_mat1, sz_mat2, sz_y ] = cssm_
sad = dir('simData1.mat');
sz_mat1 = sad.bytes;
sad = dir('simData2.mat');
sz_mat2 = sad.bytes;
load('simData1')
load('simData2')
sz_y = whos('y*');
end
function [write_tt,read_tt,readr_tt] = write_read_huge_vector( n1, n2 )
file_spec = 'c:\temp\write_read_huge_vector.dat';
write_tt = write( n1, n2, file_spec );
read_tt = read( n1, n2, file_spec );
readr_tt = readr( n1, n2, file_spec );
end
function elapse = write( n1, n2, file_spec )
if exist( file_spec, 'file' )
delete( file_spec )
end
vec = rand( n2, 1 );
fid = fopen( file_spec, 'a' );
tic_id = tic;
elapse = nan( n1, 1 );
for ii = 1 : n1
fwrite( fid, vec + 10*ii, 'double' );
elapse(ii) = toc( tic_id );
end
fclose( fid );
end
function elapse = read( n1, n2, file_spec )
fid = fopen( file_spec, 'r' );
tic_id = tic;
elapse = nan( n1, 1 );
for ii = 1 : n1
vec = fread( fid, n2, '*double' );
elapse(ii) = toc( tic_id );
end
fclose( fid );
end
function elapse = readr( n1, n2, file_spec )
fid = fopen( file_spec, 'r' );
tic_id = tic;
elapse = nan( n1, 1 );
jj = 0;
chunk_list = randperm( n1, n1 );
for ii = chunk_list
fseek( fid, (ii-1)*n2*8, 'bof' );
vec = fread( fid, n2, '*double' );
if abs( vec([1,2,3,numel(vec)-1,numel(vec)] )-10*ii ) > 1
warning( 'write_read_huge_vector:readr:Mismatch' ...
, 'reading mismatch for ii=%u', ii )
end
jj = jj + 1;
elapse(jj) = toc( tic_id );
end
fclose( fid );
end