我正在使用以下短程序来测试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; }
但是,在等待几秒钟输入“虚拟”值后,我得到以下输出:
CLOCKS_PER_SEC: 1000000 Begin: 13504 End: 13604 Difference: 100
这显然没有多大意义.无论我等多久,差异总是在100左右.
我错过了什么?我忘了包含一些标题吗?
我正在使用Xcode和GCC 4.2.