看了一本书 delphi灵感编程 提示是 :int PriorityClass;
int Priority;
const int delay=500;
DWORD TimerLo;
DWORD TimerHi;
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(delay);
asm
dw 310Fh
sub eax,TimerLo
sbb edx,TimerHi
mov TimerLo,eax
mov TimerHi,edx
end;
SetThreadPriority(GetCurrentThread,Priority);
SetPriorityClass(GetCurrentProcess,PriorityClass);
但是编译通不过 C:\myc++ test\cputest.cpp(44) : error C2059: syntax error : 'bad suffix on number'
C:\myc++ test\cputest.cpp(44) : error C2061: syntax error : identifier 'dw'
int Priority;
const int delay=500;
DWORD TimerLo;
DWORD TimerHi;
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(delay);
asm
dw 310Fh
sub eax,TimerLo
sbb edx,TimerHi
mov TimerLo,eax
mov TimerHi,edx
end;
SetThreadPriority(GetCurrentThread,Priority);
SetPriorityClass(GetCurrentProcess,PriorityClass);
但是编译通不过 C:\myc++ test\cputest.cpp(44) : error C2059: syntax error : 'bad suffix on number'
C:\myc++ test\cputest.cpp(44) : error C2061: syntax error : identifier 'dw'
将线程优先级提升为最高,再插入汇编代码测速啊!不过其实Windows注册表中就包含了中央处理器的信息(以Win2000为例)[HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0][~MHz] : CPU赫兹数;
[ProcessorNameString] : 中央处理器名称;
[Identifier] : 中央处理器识别子(包含家族信息).[FloatingPointProcessor\\0]下还有符点处理器的信息。应该够用了吧:)