Are structures really slower than numeric variables?



Dear all,

I have the following "bottleneck" line in a loop,

U = sum(Pu .* [n.K ; U]);

where, for a large integer N,
U is an Nx1 matrix,
n.K is an Nx2 matrix, part of a large structure n
Pu is an Nx3 matrix.

It appears that if I 'extract' the array K beforehand,
K=n.K;

the resulting code
U=sum( Pu .* [K ; U]);

runs significantly faster.

Am I imagining this, or is there an explanation? I would rather avoid duplicating n.K, to save memory.

Thanks for your help.
Akim
.



Relevant Pages

  • Re: Are structures really slower than numeric variables?
    ... I have the following "bottleneck" line in a loop, ... U is an Nx1 matrix, ... n.K is an Nx2 matrix, part of a large structure n ... It appears that if I 'extract' the array K beforehand, ...
    (comp.soft-sys.matlab)
  • RE: reference counting and PyTuple_SetItem
    ... is truly the bottleneck, then it *may* be good to trade off maintainability ... But what you're doing in the C loop here is almost certainly ... at all -- it's buying you bugs, but I'm not sure it's buying you anything ...
    (comp.lang.python)
  • Re: bytes To Hex
    ... if i have a long loop ..i tend to do as little stack pops as i can ... which tends to bottleneck a lot more. ... paragon of readability. ... StringBuilder isn't a cure-all for string performance problems. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: exhaustive switch bound checking
    ... Artem Alimarine a écrit: ... this dispatch is done in a loop. ...
    (microsoft.public.vc.language)
  • Re: Find the lowest value in an array
    ... is a likely bottleneck. ... I never claimed it was more readable, I claimed "to maximize efficiency". ... Unrolling the loop as I did was 20% faster. ...
    (microsoft.public.dotnet.languages.csharp)