> Why not just count and average the number of CPU cycles for a > sufficient 
> number of repetitions to determine which asm code is fastest?
 
Yeah, I think that is a good idea.
 
But user program can get swapped off for a while by the kernel, for short code 
the timing
could also be off even for a large number of runs.
 
If you need more precision I'd like to suggest an improved way:
 
1. Run a large number of loops, take TSC difference (cycle counts) of the 
interested
code segment within the loop and record them separately;
 
2. Then, run some statistical analysis on the data and reject the outliers;
 
3. Finally, take the average and whatever else you need (standard deviations, 
etc.).
 
In this way, you can effectively eliminate the extra delays introduced by 
context switches.
 
Adam Wu
.dlrow eht htiw thgir s'lla ,nevaeh sih ni si doG> Date: Fri, 31 Aug 2007 
14:34:26 +0200> To: [email protected]> From: [EMAIL PROTECTED]> Subject: Timing 
ASM> > Ken Adam wrote:> > >I can't see what use the smallest time is to you 
(since you can't make it> >happen every time without already knowing the 
result!)> > on 12 June 2003, Rob Kennedy wrote in response to my posting:> > > 
Many years ago I used:> >> > Function RDTSC : Comp;> > Var> > TimeStamp : 
Record> > case byte of> > 1 : (Whole:comp);> > 2 : (Lo, Hi : Longint);> > end;> 
> begin> > asm> > db $0F;> > db $31;> > mov [Timestamp.Lo],eax> > mov 
[Timestamp.Hi],edx> > end;> > Result := TimeStamp.Whole;> > end;> > Rob 
replied:> > "Now that Comp has fallen by the wayside due to Int64's 
introduction..."> > function RDTSC: Int64;> // Read time-stamp code> asm> db 
$0f, $31> end;> > "I've read that Delphi 6 and Kylix will actually recognize 
the mnemonic:"> > function RDTSC: Int64;> asm> rdtsc> end;> > Why not just 
count and average the number of CPU cycles for a > sufficient number of 
repetitions to determine which asm code is fastest?> > Irwin Scollar > > 
_______________________________________________> Delphi mailing list -> 
[email protected]> http://www.elists.org/mailman/listinfo/delphi
_________________________________________________________________
Windows Live Custom Domain,您的免费电子邮局。
https://domains.live.com/default.aspx
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to