From: anton@nospicedham.mips.complang.tuwien.ac.at   
      
   James Harris writes:   
   >Loops may well be OK for large chunks of code but IME things can 'go   
   >wrong' with timing short sequences of just a few instructions. Not sure   
   >why but some possible candidates: alignment in the code cache (with or   
   >without trace-cache effects), residual effects of prior and subsequent   
   >code, loop overheads, the effect of extra jumps, and interrupts being   
   >run in the background.   
      
   Yes, I recently had a case where I removed some unused code, and the   
   program slowed down by IIRC 5% on a Skylake (presumably from different   
   code alignment).   
      
   >For short sequences of code I found it best to run them either just once   
      
   I expect the same code alignment problems.   
      
   >or, preferably, to run a few as an unrolled loop.   
      
   That should help.   
      
   One very important thing is whether the computations one benchmarks   
   are independent of each other (then you measure throughput), or   
   dependent on each other (then you measure latency). And of course,   
   for code sequences involving branches, the predictability of the   
   branches is an important issue.   
      
   - anton   
   --   
   M. Anton Ertl Some things have to be seen to be believed   
   anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen   
   http://www.complang.tuwien.ac.at/anton/home.html   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|