File Exchange Pick of the Week

TIMEIT Benchmarking Function

Posted by Robert Bemis,

You may have noticed some recent changes in the format of this blog. Here’s what to expect on a regular basis – two topics per week.

  • On Tuesdays Doug will provide MATLAB tutorials.
  • On Fridays guest bloggers Jiro, Brett and Bob will highlight File Exchange submissions.

Bob's pick this week is timeit by Steve Eddins.

If you follow his weekly blog Steve on Image Processing you may have already seen this recent leap day post, Timing code in MATLAB. If you haven't read it yet and care about MATLAB performance, check it out. Steve's explanation is nice. He mentions other MATLAB performance resources. And like all good M-file submissions it includes examples like this.

A = rand(12000, 400);
B = rand(400, 12000);
f = @() sum(A.' .* B, 1);
timeit(f)
ans =
      0.14863

What I love about timeit is what it does automatically so I don't have to think about. It warms up the code, decides how many times to repeat the operation, accounts for overhead and determines how long the operation took using statistics. Thank you Steve!

Do you have a favorite tip for measuring performance to share?


Get the MATLAB code

Published with MATLAB® 7.6

Comments are closed.

These postings are the author's and don't necessarily represent the opinions of MathWorks.