Sign in to follow this  

Cpu speed detection

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! This is from page www.borland.nq.pl:

const DelayTime = 500;
DWORD TimerHi, TimerLo;
Integer PriorityClass, Priority;

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
}

Sleep(DelayTime);

asm
{
dw 310Fh
sub eax, TimerLo
sbb edx, TimerHi
mov TimerLo, eax
mov TimerHi, edx
}

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

int CPUSpeed = TimerLo / (1000 * DelayTime);


The result is in Mhz. You should do this code more than once and make an average.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In every case, remember that Centrino processor have less mhz but the same horsepower of higher mhz processor. Mhz aren't an accurate way to determine the real CPU power: at least, they are a way only inside a same family of processors. Just to be sure. :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
In every case, remember that Centrino processor have less mhz but the same horsepower of higher mhz processor. Mhz aren't an accurate way to determine the real CPU power: at least, they are a way only inside a same family of processors. Just to be sure. :)


It also needs to be considered that a number of processors will not give you a constant clockrate. AMD for example advertises it's mobile speedstep type technology to be able to adjust CPU speed over 30 times a second in response to changing demands. Combined with CPU speed not mattering (Pentium M is an extreme example, but many of AMDs processors also run at a much lower clockrate while deliverying the same preformance) there just isn't any reason to measure CPU speed unless you are reporting it directly to the user. The commands used in the example source code are really meant to be used for profiling code on a development machine, not as an accurate timer for events.

Share this post


Link to post
Share on other sites

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this