Array indexing vs. pointers...

Moshe Braner braner at batcomputer.tn.cornell.edu
Sat Sep 24 06:53:51 AEST 1988


[]

I was surprised by the results of some experiments I ran on a Gould box
and on the Inmos Transputer.  In both cases the speed of bumping pointers
turned out to be similar to, or even slower than, using array indexing.
This is not too surprising for a[i], but even holds for a[i][j], where
the indexing involves a _multiplication_!!!  (I was comparing indexing
to with double-indirection, i.e. p[i][j] where p is a pointer to an array
of pointers to rows of the matrix, and also to with *p++ where p is a
pointer to an element inside a row.)  It turns out that while on
some machines (e.g., 68000) multiplication is an order of magnitude
slower than addition or shifts, on some other machines (e.g., the
transputer) multiplication is just as fast as an addition!
(The transputer is _really_ wierd: 32*32=64 bits is (slightly)
_faster_ than 32*32=32 bits...  -- they must have the hardware
calculate 64 bits in either case, and very efficiently too!)

- Moshe Braner

Cornell Theory Center, 265 Olin Hall,
Cornell University, Ithaca, NY 14853
(607) 255-9401	(Work)
<braner at tcgould.tn.cornell.edu>		(INTERNET)
<braner at crnlthry> or <braner at crnlcam>	(BITNET)



More information about the Comp.lang.c mailing list