Newsgroups: comp.sys.transputer
From: heinzle@cs.vu.nl (Heinzle HP)
Subject: Re: Time
Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
Date: Thu, 28 Apr 1994 18:17:08 GMT
Message-ID: <CozEsL.IGy@cs.vu.nl>

prreali@iiic.ethz.ch (Patrik Rene Celeste Reali) writes:
: I was measuring how long does a FOR take on a T800,
:  but the results are very strange to me!
: Perhaps I made some mistake. Could you help me? (PLEASE)
: My program:
: 
: #include <conc.h>
: #include <stdio.h>
: 
: int i,t1,t2,t3;
: 
: main() {
: 	SetTime(0); for(i=0;i<MAX;i++) ;
: 	t1=Time();
: 
: 	SetTime(0); for(i=0;i<MAX;i++) ;
: 	t2=Time();
: 	
: 	SetTime(0); for(i=0;i<MAX;i++) ;	
: 	t3=Time();
: 
: 	printf("1. time %i\n",t1);
: 	printf("2. time %i\n",t2);
: 	printf("3. time %i\n",t3);
: }
: 
: My results:
: with MAX=10000
: 1. time 310
: 2. time 310
: 3. time 310
: 
: with MAX=100000
: 1. time 2972
: 2. time 3105
: 3. time 3215
: 
: with MAX=1000000
: 1. time 29726
: 2. time 31042
: 3. time 32159
: 
: I don't understand why the first time is *always* less than the others times!
: Any help is welcome! THANKS 
  
  Well, this is my simple ( and correct? ) explanation:

  Since you defined 'i' as a global variable, it is stored and accessed
  that way. That means especially that 'i' is not stored in the current
  workspace ( stack-frame ) and cannot be accessed relative to the work-
  space-pointer ( which would be most efficient ). So 'i' might be accessed
  relative to the instruction-pointer and the offset to 'i' therefore depends
  on the position in the program. As this offset grows, it is likely that
  the number of prefix-instructions to assemble the offset also increases,
  resulting in an increased execution-time of the affected loop.
  You can check my model with the following experiments:
  1) make 'i' local to main().
  2) put 'i' and the for-loop in a function and time several calls to it.
  3) add another 3 for-loops to the program; the result should be:
	  the differences between consecutive loops vanish, as it becomes
	  more and more difficult to force the need for an additional prefix.
  
  Cheers,
     Heinz-Peter

-- 
: This is a signature archive.  Extract with your favorite finger.
: This archive ends with exit, so do not worry about trailing junk.
: --------------------------- cut here --------------------------
exit 0

