TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DANIAL GIBSON
from: DARIN MCBRIDE
date: 1997-04-10 22:02:00
subject: Re: Video

> 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...
 DG> Ok, let's see then.
Good point.  Evidence.  :-)
 DG> #include 
 DG> #include 
 DG> #include 
 DG> #include 
What's DOS.H for?  Get rid of it.
 DG>   printf("Time to do 20,000,000 x+(y<<6)+(y<<8): %i\n", (end - start));
GCC complains: int argument required, clock_t given.  (It has a lint-style 
check of printf's)  This is a warning that doesn't prevent compilation, and 
quashed with a cast to int.
 DG> I compiled it with Borland C/C++ 3.1. I compiled it in 16 bits.
 DG> Run it and see and report the results of your computer to this echo and
 DG> we will see what is truely faster. Also say what compiler, how you ran
 DG> it (under windows os/2 dos etc), and how many bits (16/32). Also what
 DG> type of computer.
Ok, GCC on P166 running Warp 4:
(skipping the common header)
x+(y<<6)+(y<<8): 182
x+y*320: 170
x+(y<<6)+(y<<8): 182
x+y*320: 169
x+(y<<6)+(y<<8): 183
x+y*320: 169
x+(y<<6)+(y<<8): 182
x+y*320: 169
x+(y<<6)+(y<<8): 182
x+y*320: 170
x+(y<<6)+(y<<8): 182
x+y*320: 169
x+(y<<6)+(y<<8): 182
x+y*320: 170
x+(y<<6)+(y<<8): 182
x+y*320: 170
x+(y<<6)+(y<<8): 182
x+y*320: 170
x+(y<<6)+(y<<8): 182
x+y*320: 170
Consistantly your shift is slower by about 6%.  This is with standard 
optimizations and debugging.  No fancy stuff here.  Putting optimization to 
-O3 obviously destroys the entire thing.  :-)
Moving over to my BBS machine, a 486 with Warp 3 Connect, I get some more 
interesting results.  It was not doing anything at the time - the modem was 
not in use, the network was not requesting files, etc.  The same executable 
(literally) was used to produce:
x+(y<<6)+(y<<8): 129
x+y*320: 134
x+(y<<6)+(y<<8): 132
x+y*320: 130
x+(y<<6)+(y<<8): 130
x+y*320: 128
x+(y<<6)+(y<<8): 131
x+y*320: 129
x+(y<<6)+(y<<8): 128
x+y*320: 129
x+(y<<6)+(y<<8): 128
x+y*320: 129
x+(y<<6)+(y<<8): 128
x+y*320: 129
x+(y<<6)+(y<<8): 128
x+y*320: 129
x+(y<<6)+(y<<8): 127
x+y*320: 127
x+(y<<6)+(y<<8): 129
x+y*320: 127
They are basically the same here.
 DG> On mine, a 686 120mhz, under windows 95, the shifting method was faster
 DG> in every instance.
Is this a Cyrix 686?
--- Maximus/2 3.01
---------------
* Origin: Tanktalus' Tower BBS (PVT) (1:342/708)

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