Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Slow repmat

Subject: Slow repmat

From: Abel

Date: 18 Oct, 2012 22:10:14

Message: 1 of 10

Can someone explain why these performance numbers are an order of magnitude different?

x = [1 2 3]';

>> tic; for i = 1:100000; repmat(x,1,10).^2;end;toc
Elapsed time is 4.612648 seconds.

>> tic; for i = 1:100000; x(:,ones(1,10)).^2;end;toc
Elapsed time is 0.354172 seconds.

Subject: Slow repmat

From: Matt J

Date: 18 Oct, 2012 22:23:14

Message: 2 of 10

"Abel" wrote in message <k5puo6$eq4$1@newscl01ah.mathworks.com>...
> Can someone explain why these performance numbers are an order of magnitude different?
>
> x = [1 2 3]';
>
> >> tic; for i = 1:100000; repmat(x,1,10).^2;end;toc
> Elapsed time is 4.612648 seconds.
>
> >> tic; for i = 1:100000; x(:,ones(1,10)).^2;end;toc
> Elapsed time is 0.354172 seconds.


The first is implemented as an mfile. The second one runs builtin code.

Subject: Slow repmat

From: Abel

Date: 19 Oct, 2012 11:14:09

Message: 3 of 10

"Matt J" wrote in message <k5pvgi$h86$1@newscl01ah.mathworks.com>...
> The first is implemented as an mfile. The second one runs builtin code.

that's obvious, but I'm not quite sure that explains an order of magnitude performance difference.

Subject: Slow repmat

From: Bruno Luong

Date: 19 Oct, 2012 12:36:08

Message: 4 of 10

"Abel" wrote in message <k5rcm1$fee$1@newscl01ah.mathworks.com>...

> that's obvious, but I'm not quite sure that explains an order of magnitude performance difference.

Of course that obviously explains. The overhead of repmat takes T to perform, the memory duplication take T/10 with the small case you test

Try similar test to replicate (1000 x 1) to (1000 x 1000) matrix and see what you get.

Bruno

Subject: Slow repmat

From: Abel

Date: 19 Oct, 2012 15:23:15

Message: 5 of 10

so is it .m-file overhead vs. built-in or memory duplication or both?

Subject: Slow repmat

From: Bruno Luong

Date: 19 Oct, 2012 16:01:13

Message: 6 of 10

> so is it .m-file overhead vs. built-in or memory duplication or both?

You can edit repmat.m and take a look the code, it calls a(one(...),...) at the end. The rest of the time is error checking, parse input, meaning overhead.

Bruno

Subject: Slow repmat

From: Abel

Date: 19 Oct, 2012 16:55:08

Message: 7 of 10

Thanks Bruno. I really appreciate your comments.

I'm just finding it hard to digest that a wrapper function (repmat) has such an impact on performance.

Subject: Slow repmat

From: dpb

Date: 19 Oct, 2012 18:01:49

Message: 8 of 10

On 10/19/2012 11:55 AM, Abel wrote:
> Thanks Bruno. I really appreciate your comments.
> I'm just finding it hard to digest that a wrapper function (repmat) has
> such an impact on performance.

Might try to run profile on repmat() and see where the time is spent
inside it...

--

Subject: Slow repmat

From: dpb

Date: 19 Oct, 2012 18:03:48

Message: 9 of 10

On 10/19/2012 11:55 AM, Abel wrote:
> Thanks Bruno. I really appreciate your comments.
> I'm just finding it hard to digest that a wrapper function (repmat) has
> such an impact on performance.

Oh, besides my other comment, this isn't new--I get almost the same
ratio of 10:1 in R14 here...

--

Subject: Slow repmat

From: Budias Aao

Date: 19 Oct, 2012 18:31:14

Message: 10 of 10

"Abel" wrote in message <k5s0lc$46n$1@newscl01ah.mathworks.com>...
> I'm just finding it hard to digest that a wrapper function (repmat) has such an impact on performance.

The problem is that calling m functions inside loops is costly

If you want speed (and future) go to Julia

http://julialang.org/

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us