Code covered by the BSD License  

Highlights from
Test Tools - Utilities for unit tests

Test Tools - Utilities for unit tests

by

 

06 Dec 2000 (Updated )

Tools that facilitate debugging or writing unit test for MATLAB functions.

[t1,t2]=time(command)
function [t1,t2]=time(command)
% TIME('command')  records time consumed to run 'command'
%
%     Without output arguments, displays a message in the MATLAB window
%     indicating how much CPU and Wall Clock time it takes to run 'command'.
%
%     CPU=TIME('command') returns the amount of CPU time consumed.
%     
%     [CPU,WCLOCK]=TIME('command') returns the amount of CPU and Wall Clock
%     time consumed.
%
%     Note that the Wall Clock time is more sensitive to system load than is
%     the CPU time.
%
%     Use TIMESIM to time Simulink models.
%
%     See also TIC, TOC, CPUTIME, TIMESIM.

% $Source: /home/stpierre/cvsroot/matlab/tools/test_tools/time.m,v $
% $Revision: 1.4 $
% $Date: 2009-07-26 20:41:24 $

% Copyright (c) 2001-2009, Jay A. St. Pierre.  All rights reserved.


tic;
cpu = cputime;

evalin('caller', command);

cpu    = cputime-cpu;
wclock = toc;

if nargout==0
  fprintf(1, 'cpu = %.2f sec, wclock = %.2f sec\n', cpu, wclock);
else
  t1 = cpu;
  t2 = wclock;
end

Contact us