Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!sri-spam!sri-unix!husc6!bbn!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.unix.questions Subject: Re: Wierd Compilers Message-ID: <282@PT.CS.CMU.EDU> Date: Mon, 2-Nov-87 11:38:24 EST Article-I.D.: PT.282 Posted: Mon Nov 2 11:38:24 1987 Date-Received: Fri, 6-Nov-87 03:27:14 EST References: <367@white.gcm> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 48 Keywords: Sun In article <367@white.gcm>, dc@gcm (Dave Caswell) writes: > > /* Program 1 */ > main() > { > int i = 500000; > > while(--i); > } > > /* Program 2 */ > main() > { > int i = 500000; > > while(i--); > } > > Does anyone have a guess why program one runs in half the time of program two? > BTW this is a SUN 3. Do a cc -S and you will see Program one has an inter-loop like: L14: subql #0x1,a6@(-0x4) jeq L15 jra L14 Program two has an inter-loop like: L14: movl a6@(-0x4),d0 subql #0x1,a6@(-0x4) tstl d0 jeq L15 jra L14 L15: I actually go out of my way to write my loops like number one. -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu