How to measure memory usage and power consumption for an algorithm programmed with Matlab??

14 views (last 30 days)
I want to know if there is any method that enables me to determine the amount of memory used by an algorithm i built with Matlab (not all Matlab as a package but application programmed with Matlab), besides Power consumption due to running this algorithm. please help. thanks in advance.

Answers (1)

Jan
Jan on 29 Dec 2014
It depends on the exact definition of "memory usage" and "power consumption". Look at this example:
v = [];
for k = 1:1e3
v = [v, rand];
end
At the end you have a vector of only 8kb (8 byte per double), but intermediately the computer must allocate and copy sum(1:1000)*8 bytes, which are more than 4MB. It depends on the operating system and other threads if freed memory is reused later on. So what exactly is "the memory usage"?
A similar problem appears for the power consumption. Modern processors adjust the working frequency to the load and the current temperature. The relation between power consumption and processing speed is not linear and it depends on the load of the other cores and the GPU also, if it is included in the processor. It matters if the processor waits for data coming from the slow RAM or if the data exist in the caches already. In consequence the total power consumption depends on the OS, other threads, the temperature inside and outside the computer and the efficiency of the power supply.
Finally the results of the measurements might depend more on the exact definition than on the used algorithm. Therefore I suggest not to invest any time for such assessments. Even measuring the processing steps versus the data size, (the big-O value) is of limited use, when the processor cache and virtual memory on hard disks must be considered.

Categories

Find more on Scope Variables and Generate Names in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!