📄 sysinfo.h
字号:
///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////!!!!!!COPY FROM WWW.BITI.EDU.CN/VBB!!!!!!!!!!!!!!!!!!//
#include <windows.h>
float measure_clock_speed();
float measure_clock_speed ()
//-------------------------------------
{
unsigned long ticks;
unsigned long cycles;
unsigned long stamp0,
stamp1;
unsigned long freq = 0;
unsigned long freq2 =0;
unsigned long freq3 =0;
unsigned long total;
unsigned long tries=0;
LARGE_INTEGER t0,t1;
LARGE_INTEGER count_freq;
if (!QueryPerformanceFrequency( &count_freq ) )
{
return 0.0f;
}
unsigned long priority_class = GetPriorityClass(GetCurrentProcess());
long thread_priority = GetThreadPriority(GetCurrentThread());
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
do
{
tries++;
freq3 = freq2;
freq2 = freq;
QueryPerformanceCounter(&t0);
t1.LowPart = t0.LowPart;
t1.HighPart = t0.HighPart;
while ( (unsigned long)t1.LowPart - (unsigned long)t0.LowPart<50)
{
QueryPerformanceCounter(&t1);
}
_asm
{
rdtsc
mov stamp0, EAX
}
t0.LowPart = t1.LowPart; // Reset Initial
t0.HighPart = t1.HighPart; // Time
while ((unsigned long)t1.LowPart-(unsigned long)t0.LowPart<1000 )
{
QueryPerformanceCounter(&t1);
}
_asm
{
rdtsc
mov stamp1, EAX
}
cycles = stamp1 - stamp0;
ticks = (unsigned long) t1.LowPart - (unsigned long) t0.LowPart;
ticks = ticks * 100000;
ticks = ticks / ( count_freq.LowPart/10 );
if ( ticks%count_freq.LowPart > count_freq.LowPart/2 )
{
ticks++; // Round up if necessary
}
freq = cycles/ticks; // Cycles / us = MHz
if ( cycles%ticks > ticks/2 )
{
freq++; // Round up if necessary
}
total = ( freq + freq2 + freq3 );
} while ( (tries < 3 ) || (tries < 20) && ((abs(3 * freq -total) > 3)
||
(abs(3 * freq2-total) > 3) || (abs(3 * freq3-total) > 3)));
if ( total / 3 != ( total + 1 ) / 3 )
{
total ++; // Round up if necessary
}
// restore the thread priority
SetPriorityClass(GetCurrentProcess(), priority_class);
SetThreadPriority(GetCurrentThread(), thread_priority);
return float(total) / 3.0f;
}
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) 10.2003 Lchrennew Personal. //
// All rights reserved. //
// Lchrennew个人 版权所有 不得抄袭 违者必究 //
/////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -