相关疑难解决方法(0)

CLOCKS_PER_SEC与std :: clock()不匹配的结果

我正在使用以下短程序来测试std::clock():

#include <ctime>
#include <iostream>

int main()
{   
    std::clock_t Begin = std::clock();

    int Dummy;
    std::cin >> Dummy;

    std::clock_t End = std::clock();

    std::cout << "CLOCKS_PER_SEC: " << CLOCKS_PER_SEC << "\n";
    std::cout << "Begin: " << Begin << "\n";
    std::cout << "End: " << End << "\n";
    std::cout << "Difference: " << (End - Begin) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

但是,在等待几秒钟输入"虚拟"值后,我得到以下输出:

CLOCKS_PER_SEC: 1000000
Begin: 13504
End: 13604
Difference: 100
Run Code Online (Sandbox Code Playgroud)

这显然没有多大意义.无论我等多久,差异总是在100左右.

我错过了什么?我忘了包含一些标题吗?

我正在使用Xcode和GCC 4.2.

c++ time xcode gcc clock

4
推荐指数
1
解决办法
1218
查看次数

标签 统计

c++ ×1

clock ×1

gcc ×1

time ×1

xcode ×1