我通常在linux中使用sysconfig(_SC_CLK_TCK)来获取时钟频率(总是返回100)。问题是我想使用dhrystone基准与Atari Mint(TOS)。我在名为ARanyM的模拟器上安装了atari mint。我在这里也使用了sysconfig(_SC_CLK_TCK),但它返回了类似于4294967295(这实际上是32位中的所有1个值)
有没有人提出任何建议?
答案 0 :(得分:0)
使用Linux我使用:
#include <time.h>
double theseSecs = 0.0;
double startSecs = 0.0;
double secs;
double CPUsecs = 0.0;
double CPUutilisation = 0.0;
double answer = 0;
clock_t starts;
void start_CPU_time()
{
starts = clock();;
return;
}
void end_CPU_time()
{
CPUsecs = (double)(clock() - starts)/(double)CLOCKS_PER_SEC;
return;
}
struct timespec tp1;
void getSecs()
{
clock_gettime(CLOCK_REALTIME, &tp1);
theseSecs = tp1.tv_sec + tp1.tv_nsec / 1e9;
return;
}
void start_time()
{
getSecs();
startSecs = theseSecs;
return;
}
void end_time()
{
getSecs();
secs = theseSecs - startSecs;
return;
}
void calculate()
{
int i, j;
for (i=1, i<1000001; i++)
{
for (i=j, j<1000001; j++)
{
answer = answer * (float)i / 1000000.0;
}
}
}
void main()
{
start_time();
start_CPU_time();
calculate();
end_time();
end_CPU_time();
CPUutilisation = CPUsecs / secs / 100.0;
printf"/n Answer %8.3f, Elapsed Time %7.4f, CPU Time %7.4f,
CPU Utilisation %8.4f/n, answer, secs, CPUsecs, CPUutilisation);
}