【问题标题】:Counting time or cpu clicks in Cygwin在 Cygwin 中计算时间或 cpu 点击次数
【发布时间】:2013-04-19 18:24:06
【问题描述】:

我无法计算 cygwin 中 cpu 处理的时间?这是为什么呢? 我需要一个特殊的命令吗?计算 cpu 中的点击次数是由时钟完成的 包含 time.h 后的函数!

仍然,在我在 Visual Studio 中完成后,我无法在 cygwin 上运行? 为什么会这样!

这里是代码。

#include <iostream>
#include <time.h>
using namespace std;
int main()
{

    clock_t t1,t2;

    int x=0;
    int num;
    cout << "0 to get out of program, else, number of iterations" << endl;
    cin>>num;

    if(num==0)
    system(0);
    t1=clock();
    while (x!=num)
        {
        cout << "Number "<<x<<" e"<< endl;
        if(x%2==0)
            cout << "Even" << endl;
        else
            cout << "Odd" << endl;
        x=x+1;
        }


    t2=clock();
    float diff ((float)t2-(float)t1);
    cout<<diff<<endl;
    float seconds = diff / CLOCKS_PER_SEC;
    cout<<seconds<<endl;
    system ("pause");
    return 0;
}

抱歉英语不好。

【问题讨论】:

    标签: time cygwin cpu time.h


    【解决方案1】:

    看起来 clock() 函数对 Windows 和 POSIX(以及 Cygwin)的定义不同。 MSDN 说 Windows clock() 返回“自进程启动以来经过的挂钟时间”,而 POSIX 版本返回“实现对进程使用的处理器时间的最佳近似值”。在您的示例中,该进程将花费几乎全部时间等待终端的输出完成,这不计入处理时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 2014-05-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多