Funkcja w assemblerze testująca prędkość procesora.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
function TForm1.GetCpuSpeed: Extended; var t: DWORD; mhi, mlo, nhi, nlo: DWORD; t0, t1, chi, clo, shr32: Comp; begin shr32 := 65536; shr32 := shr32 * 65536; t := GetTickCount; while t = GetTickCount do begin end; asm DB 0FH DB 031H mov mhi,edx mov mlo,eax end; while GetTickCount < (t + 1000) do begin end; asm DB 0FH DB 031H mov nhi,edx mov nlo,eax end; chi := mhi; if mhi < 0 then chi := chi + shr32; clo := mlo; if mlo < 0 then clo := clo + shr32; t0 := chi * shr32 + clo; chi := nhi; if nhi < 0 then chi := chi + shr32; clo := nlo; if nlo < 0 then clo := clo + shr32; t1 := chi * shr32 + clo; Result := (t1 - t0) / 1E6; end; |
Powyższą procedurę umieszczamy w dowolnym miejscu w unicie. Teraz wyświetlmy prędkość na labelu.
1 2 3 4 5 6 7 |
procedure TForm1.Button1Click(Sender: TObject); begin label1.Caption := FloatToStr(GetCpuSpeed) + 'mhz'; end; |
Autor: Nakiel