Skip to content

Instantly share code, notes, and snippets.

@sajith
Created May 17, 2012 20:04
Show Gist options
  • Save sajith/2721280 to your computer and use it in GitHub Desktop.
Save sajith/2721280 to your computer and use it in GitHub Desktop.
silly Matlab function to show load times of .mat files under a directory
function loadtimes ( dirname )
if isempty ( dirname ), return, end
cmd = sprintf ( 'find %s -iname "*.mat"', dirname );
[ ~, files ] = system ( cmd );
mfiles = regexp ( files, '\n', 'split');
for i = 1 : length ( mfiles ) - 1
s1 = sprintf ( '%s', mfiles{i} );
s = regexprep ( s1, ',$', '' );
d = dir ( s );
fprintf ( '%s, %s, %d bytes, \t', s, bytes2h ( d.bytes ), d.bytes );
tic; load ( s ); toc;
end
return
function [sz] = bytes2h ( bytes )
if ( bytes < 1024 )
sz = sprintf ( '%d bytes', bytes );
elseif ( bytes < 1024 * 1024 )
sz = sprintf ('%0.2f KiB', bytes / 1024 );
elseif ( bytes < 1024 * 1024 * 1024 )
sz = sprintf ('%0.2f MB', bytes / ( 1024 * 1024 ) );
end
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment