File Exchange Pick of the Week

March 28th, 2008

TIMEIT Benchmarking Function

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

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

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