Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Jun 2000 17:07:42 -0700
From:      Zach Brown <zab@zabbo.net>
To:        hackers@FreeBSD.ORG
Subject:   Re: Optimization
Message-ID:  <20000605170742.C9146@mrnutty.zabbo.net>
In-Reply-To: <20000606025717.A40896@happy.checkpoint.com>; from Anatoly Vorobey on Tue, Jun 06, 2000 at 02:57:18AM %2B0300
References:  <200006052347.IAA00583@daniel.sobral> <20000606025717.A40896@happy.checkpoint.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000605170742.C9146>