Timing your Code

In Matlab, it is very easy to see how long a section of code took. The functions to use are: clock() and etime().

Timing Code

The function "clock" gives you the current time of day. The data type for this time is an array of numbers representing, the day, month, year, hour, minute, and second. The etime function tells you the elapsed time between a "start time" and an "end time".

	
	  start_time = clock(); % get the original time

	  % DO CODE HERE (call functions, run scripts, etc)

	  elapsed_time = etime(clock(), start_time);

	  fprintf('it took %d seconds\n', elapsed_time);
	
      

Alternatively, you can use the tic and toc commands:

	
	  tic

	  % DO CODE HERE (call functions, run scripts, etc)

	  toc

	
      

Back to Topics List