TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CHRIS DOWNS
from: NIELS JONKER
date: 1997-04-08 21:26:00
subject: Re: Video

 x+(y<<6)+(y<<8) vs x+y*320
 CD> It would be easy enough to benchmark the code and that's the _only_ way
 CD> you could get a good answer to the question. 
Indeed you're right, so I coded a little bit to do this.
I tried it on a pentium 60 compiled for DOS 16 bit with BC 4.02 with 
various optimization switches, in each case the shifts were quitte a bit
faster then the multiplication.
for 500 loops
bcc switches : default  -O2    -G
shifts       : 2.69s    2.03s  2.15s       
mul          : 4.28s    4.29s  3.79s
but to get an answer for the machine and compiler you're writing your code 
for just compile the below and see what you get, (I believe the timing 
routines are borland specifiek, so you might have to change this for other
compilers)
Niels...
/* --------------------------------------------------------------------- */
#include 
#include 
void Shifts(unsigned char *Ptr,unsigned char val)
{
	int x,y;
	for(x=0;x<320;x++)
	{
		for(y=0;y<100;y++)
		{
			Ptr[x+(y<<6)+(y<<8)] = val;
		}
	}
}
void Mul(unsigned char *Ptr,unsigned char val)
{
	int x,y;
	for(x=0;x<320;x++)
	{
		for(y=0;y<100;y++)
		{
			Ptr[x+y*320] = val;
		}
	}
}
int main()
{
	int times = 500;
	int n;
	clock_t clockticks;
	unsigned char buf[32001];
	cout << "checking 2 shifts + 2 adds vs 1 mul + 1 add" << endl;
	clockticks = clock();  // get time
	for(n=0;n * Origin: Free sex on Softwareboard 0224-218587 {+} Reg.Only (2:280/112)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.