How to best time differences between function implementations
3 views (last 30 days)
Show older comments
Following on from a comment to this question: http://www.mathworks.co.uk/matlabcentral/answers/35676-why-not-use-square-brackets
If you have two functions, funA and funB, what is the best way to test if funA takes a different amount o time from funB? Do you use tic/toc, a java timing object, a mex to get the execution times. Once you have the execution times what do you do? As a concrete example consider
funA = @()1:10;
funB = @()[1:10];
0 Comments
Answers (1)
Jan
on 19 Apr 2012
For short tests I call something like this from the command line:
tic; for i = 1:1e5, a = funA; clear('a'); end, toc
The clearing avoids surprising JIT effects, most of all when a Mex function is tested. Although the JIT is affected by writing several commands in one line also, I did not see substantial deviations compare to timings measured by creating an M-file with one command per line.
See Also
Categories
Find more on Performance and Memory 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!