Performance tuning - finding CPU time
Ältere Kommentare anzeigen
Hi -
I have a Matlab function (my code) that takes about 1.5ms to run most of the time, but every once in a while spikes up - 10ms, 15ms, 20ms, or even higher. I would like to figure out why.
I may have to do this with other functions in future - so my question is not about this specific piece of code, but rather about how to debug this type of a problem in Matlab.
1) tic/toc - Above timings were done using tic/toc. Natural question is - since I am measuring elapsed time, are my outlier purely due to things like thread switches, etc. etc.? If so, would setting processor affinity of the Matlab process help?
2) cputime - I tried using cputime - for a lot of my calls, the cputime returns zero even when tic/toc returns a non-zero value. Has anyone experienced this?
3) Profiler - Pretty useless in this case I think - it reports average times. Well, on average, the function performs just fine. I am trying to track down the outliers, and I don't quite see how the Profiler can be helpful here.
Thanks in advance! matal
Antworten (3)
per isakson
am 19 Jul. 2013
Bearbeitet: per isakson
am 19 Jul. 2013
See
They link to other resources on timing.
BTW: Which OS do you use?
.
cputime
First time ever(?) I try cputime. The resolution is poor (0.0156s on Windows 7, R2012a 64bit). That's why you see ZERO.
>> t = cputime; surf(peaks(40)); e = cputime-t
e =
0.2028
>> t = cputime; surf(peaks(40)); e = cputime-t
e =
0.0624
>> t = cputime; surf(peaks(40)); e = cputime-t
e =
0.0156
>> t = cputime; surf(peaks(40)); e = cputime-t
e =
0.0156
>> t = cputime; surf(peaks(40)); e = cputime-t
e =
0.0312
>> t = cputime; surf(peaks(40)); e = cputime-t
e =
0.0156
>> t = cputime; surf(peaks(40)); e = cputime-t
e =
0
6 Kommentare
matal
am 19 Jul. 2013
matal
am 19 Jul. 2013
per isakson
am 19 Jul. 2013
Bearbeitet: per isakson
am 19 Jul. 2013
1) TIMEIT runs the function several times, excludes the first (few?) and report an average for the rest. More important than the code is the rational for TIMEIT.
2) AFAIK: Yes! (I'm not sure about the status of this "issue", whether it is a BUG with an ID and all that.)
The behavior, "spikes", you report is not typical - I dare to say. Have you seen it with many different m-files?
matal
am 19 Jul. 2013
matal
am 19 Jul. 2013
per isakson
am 19 Jul. 2013
Bearbeitet: per isakson
am 19 Jul. 2013
Regarding the "inner workings" Matlab is a black box and The Mathworks wants too keep it that way.
"scientifically establish the exact line(s) of code that are resulting in the spikes." Sounds difficult to me. Don't forget the accelerator and just-in-time-compiler.
Yair Altman
am 20 Jul. 2013
Bearbeitet: Yair Altman
am 20 Jul. 2013
1 Stimme
The Profiler DOES provide detailed information about specific call invocations, but you need to dig a bit in its undocumented raw data. This is explained here: http://undocumentedmatlab.com/blog/undocumented-profiler-options-part-3/
Naturally, the raw data begs for someone to write a utility that presents the info in a more human-readable manner. I would have done it myself if I had any time - maybe someone else will pick up the glove (Jan? Per? anyone?)
1 Kommentar
matal
am 22 Jul. 2013
Jan
am 19 Jul. 2013
0 Stimmen
Measuring the timing can be influenced by other applications also. E.g. the garbage collection of the operating system's memory manager. Or the WLAN adapter checks the connection. I do not think that the source of the delays can be reliably determined in every case. So a strategy for measuring timings is to exclude the outliers from the statistics.
1 Kommentar
matal
am 22 Jul. 2013
Kategorien
Mehr zu Historical Contests finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!