• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 572
  • Last Modified:

Processor speed?

Hi
How to find out a speed of processor in Delphi code?

 thx!
0
neox
Asked:
neox
1 Solution
 
kwang080897Commented:
I Dont know how this works, but i works thanks to someone on Experts Exchange (dont remember who).

A good advise :

Check some of the previos answered questionon this side:
There is a lot of good stuff (Cheap)




function tmainform.GetCPUSpeed: String;
var
  t: DWORD;
  mhi, mlo, nhi, nlo: DWORD;
  t0, t1, chi, clo, shr32: Comp;
begin
  try
    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 := Format('%.0f MHz', [(t1 - t0) / 1E6])

  except
    Result := 'Ukendt';
  end;
end;


Kim
0
 
andreifCommented:
Another version, it's not my code, but may be useful.

function GetCPUSpeed: Double;
const
  DelayTime = 500;
var
  TimerHi : DWORD;
  TimerLo : DWORD;
  PriorityClass : Integer;
  Priority : Integer;

begin
  PriorityClass := GetPriorityClass(GetCurrentProcess);
  Priority := GetThreadPriority(GetCurrentThread);
  SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
  SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);

  Sleep(10);

  asm
    DW 310Fh
    MOV TimerLo, EAX
    MOV TimerHi, EDX
  end;

  Sleep(DelayTime);

  asm
    DW 310Fh
    SUB EAX, TimerLo
    SBB EDX, TimerHi
    MOV TimerLo, EAX
    MOV TimerHi, EDX
  end;

  SetThreadPriority(GetCurrentThread, Priority);
  SetPriorityClass(GetCurrentProcess, PriorityClass);

  Result := TimerLo / (1000.0 * DelayTime);
end;

//USAGE:

Label1.Caption := Format('CPU speed: %f MHz', [GetCPUSpeed]);
0
 
intheCommented:
andreif ,
you should only post your suggestion as a comment as kwang has already posted a coment that works ..
0
 
bryan7Commented:
listenning
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now