On Tue, Jun 06, 2000 at 02:57:18AM +0300, Anatoly Vorobey wrote:

> > Can someone discuss the performance trade-offs of the following two
> > alternative codes (and maybe suggest alternatives)?
> > 
> > Problem: I need to retrieve two values from a table.
> > 
> > Alternative A:
> > 
> >     x = table[i].x;
> >     y = table[i].y;
> > 
> > Alternative B:
> > 
> >     d = table[i];
> >     x = d & MASK;
> >     y = d >> SHIFT;
> 
> Alternative A should be much faster. The compiler should be smart 

Don't forget the effects of caching.  If x/y are always referenced
together, and memory is slow slow slow (on, say, any processor made in
the last few years)  then the cost of unmushing the data in the cpu
could be much cheaper than the cost of going to memory to get x and y
from different tables.   It all depends on access patterns.

do some benchmarking.  extra credit for using cpu counters to get Real
Numbers :)   http://www.fz-juelich.de/zam/PCL/doc/pcl/pcl.html

-- 
 zach


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to