[Fwd: [OctDev] slow structs]

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Fwd: [OctDev] slow structs]

Daniel Sebald


-------- Original Message --------
Subject: [OctDev] slow structs
Date: Wed, 17 Dec 2008 18:13:17 -0600
From: Jonathan Kotta <[hidden email]>
To: [hidden email]

I have a problem where a vector within a struct is much slower to
index than a plain vector (~8x slower) .

x = zeros(1e6,1);
s.x = x;
subset = 500e3:600e3-1;
y = randn(length(subset),1);
for i = 1:5
   tic; x(subset) = y; toc;
end
for i = 1:5
   tic; s.x(subset) = y; toc;
end
tic;
for i = 1:100
   x(subset) = y;
end
toc;
tic;
for i = 1:100
   s.x(subset) = y;
end
toc;

Tested using Octave 3.0.3 on x86-64.

--
Thanks,

Jonathan Kotta

Hofstadter's Law:
    It always takes longer than you expect, even
    when you take into account Hofstadter's Law.

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Octave-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/octave-dev


--

Dan Sebald
email: daniel(DOT)sebald(AT)ieee(DOT)org
URL: http://www(DOT)dansebald(DOT)com
Reply | Threaded
Open this post in threaded view
|

[Fwd: [OctDev] slow structs]

John W. Eaton
Administrator
On 17-Dec-2008, Daniel J Sebald wrote:

| Subject: [OctDev] slow structs
| Date: Wed, 17 Dec 2008 18:13:17 -0600
| From: Jonathan Kotta <[hidden email]>
| To: [hidden email]
|
| I have a problem where a vector within a struct is much slower to
| index than a plain vector (~8x slower) .
|
| x = zeros(1e6,1);
| s.x = x;
| subset = 500e3:600e3-1;
| y = randn(length(subset),1);
| for i = 1:5
|    tic; x(subset) = y; toc;
| end
| for i = 1:5
|    tic; s.x(subset) = y; toc;
| end

Accessing a structure element requires looking up the element in a map
using the field name (a character string).  You don't expect that
would be free, do you?

jwe
Reply | Threaded
Open this post in threaded view
|

Re: [Fwd: [OctDev] slow structs]

jpkotta
On 12/17/08, John W. Eaton <[hidden email]> wrote:

> On 17-Dec-2008, Daniel J Sebald wrote:
>
>  | Subject: [OctDev] slow structs
>  | Date: Wed, 17 Dec 2008 18:13:17 -0600
>  | From: Jonathan Kotta <[hidden email]>
>  | To: [hidden email]
>
> |
>  | I have a problem where a vector within a struct is much slower to
>  | index than a plain vector (~8x slower) .
>  |
>
> | x = zeros(1e6,1);
>  | s.x = x;
>  | subset = 500e3:600e3-1;
>  | y = randn(length(subset),1);
>  | for i = 1:5
>  |    tic; x(subset) = y; toc;
>  | end
>  | for i = 1:5
>  |    tic; s.x(subset) = y; toc;
>  | end
>
>
> Accessing a structure element requires looking up the element in a map
>  using the field name (a character string).  You don't expect that
>  would be free, do you?
>
>
>  jwe
>

No, I guess I just didn't expect it to be that much slower.  Anyway, I
think I solved my original problem; my example was a simplified
version of it.  Thanks for the replies.


--
Thanks,

Jonathan Kotta

Hofstadter's Law:
    It always takes longer than you expect, even
    when you take into account Hofstadter's Law.