Pentium Optimisations
By mindweaver@technologist.com
Instruction Timing
To time the number of clock cycles that a block of code takes you can use the rdtscMM84RZ instruction. See it's entry for full information.
The following code ultimately sets eax to the number of clock cycles taken by the usercode: -
rdtsc // get CPU clocks
mov clocks,eax // save clock counter
[usercode]
rdtsc // get CPU clocks
mov ecx, clocks // get the old clock counter
sub eax, ecx // calc clock cycles taken
sub eax, $0E // subtract clocks wasted on rdtsc's
Where clocks is a 32-Bit variable.
If you are using assembly embedded in a high level language your assembler might not support the rdtsc mnemonic, as Borland Delphi 3 doesn't. In this case you can use the following construct in place of the rdtsc instruction: -
dw $310F // two bytes in hex
Note that if the code being timed is quite long, the time value might not be acurate due to interupts occuring during your code execution.
Created with the Personal Edition of HelpNDoc: Full-featured Help generator