![]() w = waitbar(0, 'My Progress Bar') % create a new waitbar, w with 0% progress for i=1:500 (To be precise, Octave has a waitbar function, but does not support all of the same operations, e.g. Note, however, that this doesn't currently work in Octave. MATLAB's graphical progress bar can be a useful tool for getting a sense of how long operations are taking, particularly ones involving loops. Note that the process of publishing this document can throw off the timing results - try the code out for yourself. Tom Minka has written some flop counting routines as part of his lightspeed package. MATLAB used to have a flops command, but it was removed. ![]() While this is usually very fast, you will sometimes notice that a function is faster to execute the second time round. The first time a function is called, MATLAB generates an optimized p-code file. A more reliable method is the timeit function, which calls tic/toc multiple times and averages. The simplest way to time code is to call tic before your code starts and toc afterwords. The profiler tells you where all the time is being spent, but maybe you just want to know how much time your code is taking. Once profiling is on, execute your code, and then type profile viewer to see the report. You can turn on profiling with the profile on command and turn it off again with profile off. You can click on a function name to bring up its sourcecode. This is really the statistic you should pay attention to. ![]() Self-time, denoted by a dark blue band, is the time spent within a function not including how long was spent in functions called from here. The report shows a breakdown of all the functions called from your function, the number of times they were called, and the total time spent executing them. It automatically generates a web page summarizing the results, which you can click on to 'drill down'. MATLAB has an excellent profiler, which can tell you how much time your code spends in each one of its functions. Also, remember that correctness is more important than speed! The usual pattern is that 80% of the the time is spent in 20% of the code, so you can focus your efforts accordingly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |