School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 306,924 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,731 people online right now. Registration is fast and FREE... Join Now!




MATLAB: Measuring time and memory used by a function?

 

MATLAB: Measuring time and memory used by a function?

squarewavedreams

5 May, 2009 - 09:43 AM
Post #1

New D.I.C Head
*

Joined: 13 Mar, 2009
Posts: 5

I have a project which involves running two filters -- rcosflt() and a customized version provided by the profesor -- separately on a random array of data. In addition to the results, I need to find out how much time and memory each one took to arrive at their result. I'm completely new to MATLAB and the professor has been, well, unhelpful. Thoughts?

This post has been edited by squarewavedreams: 5 May, 2009 - 09:45 AM

User is offlineProfile CardPM
+Quote Post


paperclipmuffin

RE: MATLAB: Measuring Time And Memory Used By A Function?

8 May, 2009 - 11:25 PM
Post #2

WinWinWinWindows?
Group Icon

Joined: 16 Apr, 2009
Posts: 899



Thanked: 9 times
Dream Kudos: 400
My Contributions
Could you please post the code you have used so far?

Thank you for helping us to help you. biggrin.gif
User is online!Profile CardPM
+Quote Post

squarewavedreams

RE: MATLAB: Measuring Time And Memory Used By A Function?

9 May, 2009 - 09:21 PM
Post #3

New D.I.C Head
*

Joined: 13 Mar, 2009
Posts: 5

I hadn't written the code yet when I posted, so I apologize. Here it is so far:

CODE
Delay = 3; DataL = 20; R= .5; Fs = 8; Fd = 1;
x = round(rand([DataL,1]));
tx = (0: DataL - 1) ./ Fd + Delay / Fd;
subplot(3,1,1);
stem(tx, x, 'kx');
axis([0 30 -1.6 1.6]); xlabel('Time'); ylabel('Amplitude');
title('Unfiltered data with delay compensation');
[yf, tf] = rcosine(Fd, Fs, 'fir', R, Delay);
[yo1, to1] = rcosflt(x, Fd, Fs, 'filter', yf);
[yo2, to2] = rcos2dflt(x, Fd, Fs, yf, Delay);
subplot(3,1,2);
stem(tx, x, 'kx'); hold on;
plot(to1, yo1, 'b-'); hold off;
axis([0 30 -1.6 1.6]); xlabel('Time'); ylabel('Amplitude');
title('Filtered with rcosflt()');
subplot(3,1,3);
stem(tx, x, 'kx'); hold on;
plot(to2, yo2, 'b-'); hold off;
axis([0 30 -1.6 1.6]); xlabel('Time'); ylabel('Amplitude');
title('Filtered with two-index algorithm');


So what I need is some way to measure and report the efficiency of the rcosflt() and the custom rcos2dflt() function in lines 9 and 10 respectively. The professor simply asked to compare 'time and memory usage', but I at least need to know how much time each one takes.

EDIT: I've been told on another forum to use tic, toc, and whos to accomplish this. I'm about to start working on this, but if anyone comes up with a better solution, I'm all ears. Thanks!

This post has been edited by squarewavedreams: 9 May, 2009 - 09:28 PM
User is offlineProfile CardPM
+Quote Post

InfiniteL00P

RE: MATLAB: Measuring Time And Memory Used By A Function?

5 Nov, 2009 - 05:32 PM
Post #4

New D.I.C Head
*

Joined: 5 Nov, 2009
Posts: 11



Thanked: 1 times
My Contributions
Hello,

In order to measure the memory used by the function, all you have to do is have it saved to your current directory and enter whos <name of function> in the command window and it will return where the function is stored, data types, total memory etc.

Ex:
CODE

myfunction(some input) //Say your function was called 'myfunction'

whos myfunction //will return information about the function myfunction.m



Also, in order to measure the time it takes to run your function, just open the function in the editor, add tic where you want to start recording and then toc at the end. The time taken to execute will be printed in the command window.

Ex:
CODE

function [output] = myfunction(input)

tic //Start timer
count = 0;
idx = 0;
for idx = 1:length(input)
     if count <= length(input)
          count = count + 1
     end
end
output = count
toc //Stop Timer
end

//You could also step through your function in the debugger line by line using the tic and toc keywords.


This post has been edited by InfiniteL00P: 5 Nov, 2009 - 09:24 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 03:02AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month