请指教

解决方案 »

  1.   

    这个问题怎么没有人答?我来吧:
    function GetCPUSpeed: Double; 
    constDelayTime = 500;varTimerHi, TimerLo: DWORD;PriorityClass, Priority: Integer;begintryPriorityClass := GetPriorityClass(GetCurrentProcess);Priority := GetThreadPriority(GetCurrentThread);SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);SetThreadPriority(GetCurrentThread,THREAD_PRIORITY_TIME_CRITICAL);Sleep(10);asmdw 310Fh // rdtscmov TimerLo, eaxmov TimerHi, edxend;Sleep(DelayTime);asmdw 310Fh // rdtscsub eax, TimerLosbb edx, TimerHimov TimerLo, eaxmov TimerHi, edxend;SetThreadPriority(GetCurrentThread, Priority);SetPriorityClass(GetCurrentProcess, PriorityClass);Result := TimerLo / (1000.0 * DelayTime);exceptResult := 0;end;end;*************在VC中用以下代码可以测出CPU的主频:static int time[2]int cpuclock;在InitInstance中SetTimer(hWnd,1,1000,NULL)在消息处理过程中case WM_CREATE;_asm{rdtsc //一个64bit的时间标记计数器mov ecx,offset timemov [ecx+0],edxmov [ecx+4],eax}break;case WM_TIMER:_asm{rdtscmov ebx,offset timesub eax,[ebx+4]sbb edx,[ebx+0]mov ecx,1000000div ecxmov cpuclock,eax}但不知在DELPHI中如何编程测试?还有CPU的类型等等! --------------------------------------------------------------------------------来自:cat.yy 时间:00-12-29 16:17:03 ID:427844SetTimer(handle,1,1000,NULL);......(var msg: message)...if msg.message=WM_CREATE thenbeginasmrdtsc //一个64bit的时间标记计数器mov ecx,offset timemov [ecx+0],edxmov [ecx+4],eaxend;end;if msg.message=WM_TIMER thenbeginasmrdtscmov ebx,offset timesub eax,[ebx+4]sbb edx,[ebx+0]mov ecx,1000000div ecxmov cpuclock,eaxend;end;*************function TForm1.GetCpuSpeed: Extended;vart, mhi, mlo, nhi, nlo: dword;shr32 : comp;beginshr32 := 65536;shr32 := shr32 * 65536;t := GetTickCount;while t = GetTickCount do ;asmDB 0FH,031H // rdtscmov mhi,edxmov mlo,eaxend;while GetTickCount < (t + 1000) do ;asmDB 0FH,031H // rdtscmov nhi,edxmov nlo,eaxend;Result := ((nhi * shr32 + nlo) - (mhi * shr32 + mlo)) / 1E6;end;