Path: utzoo!attcan!uunet!husc6!mailrus!cornell!batcomputer!braner From: braner@batcomputer.tn.cornell.edu (Moshe Braner) Newsgroups: comp.lang.c Subject: Re: Array indexing vs. pointers... Summary: Not always faster to use pointers! Message-ID: <6396@batcomputer.tn.cornell.edu> Date: 23 Sep 88 20:53:51 GMT References: <8809191521.AA17824@ucbvax.Berkeley.EDU> <68995@sun.uucp> Reply-To: braner@tcgould.tn.cornell.edu (Moshe Braner) Organization: Cornell Theory Center, Cornell University, Ithaca NY Lines: 24 [] 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)(INTERNET) or (BITNET)