TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: DANIAL GIBSON
date: 1997-04-07 17:11:00
subject: Re: Video

>  //Screen[x+y*320] = color;
>  Screen[x+(y<<6)+(y<<8)] = color; /* same as above but here the
>          multiplication is replaced with
>          shifts to make it faster */
> Are you SURE that two shift operations followed by an addition is
> really faster than the hardware-optimized integer multiplication?
> Perhaps on an 8086... but on an 80486?  Probably not...
Ok, let's see then.
#include 
#include 
#include 
#include 
void main(void)
{
 int x, y, loop;
 long counter, i;
 clock_t start, end;
 for (loop=0; loop<10; loop++) { // do the test 10 times
  start = clock();
  for (counter=0; counter<20000000; counter++) {
   i=x+(y<<6)+(y<<8);
  }
  end = clock();
  printf("Time to do 20,000,000 x+(y<<6)+(y<<8): %i\n", (end - start));
  start = clock();
  for (counter=0; counter<20000000; counter++) {
   i=x+y*320;
  }
  end = clock();
  printf("Time to do 20,000,000 x+y*320: %i\n", (end - start));
 }
}
I compiled it with Borland C/C++ 3.1. I compiled it in 16 bits.
Run it and see and report the results of your computer to this echo and
we will see what is truely faster. Also say what compiler, how you ran
it (under windows os/2 dos etc), and how many bits (16/32). Also what
type of computer.
On mine, a 686 120mhz, under windows 95, the shifting method was faster
in every instance.
Danial.
___
 X SLMR 2.1a X 
--- Maximus/2 3.00
---------------
* Origin: Hunter Connection OS/2 BBS 24hrs (049) 57-1801 (3:622/403)

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™.