1 2 (* NOTE: this may not work on all computers due to hardware limitations. *)3 4 function RDTSC : Int64; assembler;
5 asm
6 db $0F, $31 // opcode for RDTSC7 end;
8 9 function RDQPC : Int64;
10 begin11 //retrieves the current value of the high-resolution performance counter, if one 12 //exists.13 QueryPerformanceCounter(result);
14 end;
15 16 function CPUSpeed : Integer;
17 var18 f, tsc, pc : Int64;
19 begin20 //etrieves the frequency of the high-resolution performance counter, if one exists.21 if QueryPerformanceFrequency(f) then22 begin23 Sleep(0);
24 pc := RDQPC;
25 tsc := RDTSC;
26 Sleep(100);
27 pc := RDQPC-pc;
28 tsc := RDTSC-tsc;
29 result := round(tsc * f / (pc * 1000000));
30 end31 else32 result := -1;
33 end;