时钟() [英] clock()

查看:64
本文介绍了时钟()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我试图确定boost.timer是如何工作的,我尝试了一些

的东西,而且不会。所以我打开标题来查看原因并运行

一些测试来确定发生了什么,这一切都归结为

clock()函数。以下是代码:

#include< iostream>

#include< cstdlib>


int main(void)

{

boost :: timer tmr;

sleep(15);


std: :cout<< std :: clock()<< std :: endl;


返回0;

}

该程序始终输出0。关于clock()的文档说它自从程序启动以来它应该返回时钟滴答,其中15 / b
的第二次睡眠应该是充足的。我不明白。

解决方案

clock()函数返回
$使用的处理器时间的近似值b $ b程序。


但sleep()函数不使用处理器时间。


> ro**********@gmail.comw 死记硬背:

好​​的,所以我试图确定boost.timer是如何工作的,我尝试了一下

几个

事情,并且它没有。所以我打开标题看看为什么和
运行一些测试来确定发生了什么,这一切都归结为
clock()函数。以下是代码:

#include< iostream>
#include< cstdlib>

int main(无效)
{
boost :: timer tmr;

sleep(15);

std :: cout<< std :: clock()<< std :: endl;

返回0;
}

该程序始终输出0。关于clock()的文档说
它应该在程序启动后返回时钟滴答,其中15/2秒睡眠应该是充足的。我不明白。




#include< ctime>

#include< cstdlib>

#include< iostream>


使用命名空间std;


int main()

{

sleep(10);

cout<< clock()<<结束;

返回0;

}

输出15。




JetSnaiL写道:

ro ********** @ gmail.comw 死记硬背:


好的,所以我试图确定boost.timer的工作方式和我尝试一下
几个

事情,并且不会。所以我打开标题看看为什么和


运行

一些测试来确定发生了什么,这一切都归结为


< blockquote class =post_quotes> clock()函数。以下是代码:

#include< iostream>
#include< cstdlib>

int main(无效)
{
boost :: timer tmr;

sleep(15);

std :: cout<< std :: clock()<< std :: endl;

返回0;
}

该程序始终输出0。关于clock()的文档说


应该返回自程序启动以来的时钟滴答,这应该是足够的第二次睡眠。我不明白。



#include< ctime>
#include< cstdlib>
#include< iostream>

使用命名空间std;

int main()
{
睡眠(10);
cout<< clock()<< endl;
返回0;
}

输出15。




好​​吧,我得到0。


Ok, so I am trying to establish how boost.timer works and I try a few
things and afaict it doesn''t. So I open the header to see why and run
some tests to establish what is going on and it all boils down to the
clock() function. Here is the code:
#include <iostream>
#include <cstdlib>

int main(void)
{
boost::timer tmr;
sleep(15);

std::cout << std::clock() << std::endl;

return 0;
}
That program always outputs "0". Documentation on clock() says that it
should return clock ticks since program started, which with the 15
second sleep that should be plenty. I don''t understand.

解决方案

The clock() function returns an approximation of processor time used by
the program.

but sleep() function not use processor time.


> ro**********@gmail.comwrote:
Ok, so I am trying to establish how boost.timer works and I try a
few

things and afaict it doesn''t. So I open the header to see why and run some tests to establish what is going on and it all boils down to the clock() function. Here is the code:
#include <iostream>
#include <cstdlib>

int main(void)
{
boost::timer tmr;
sleep(15);

std::cout << std::clock() << std::endl;

return 0;
}
That program always outputs "0". Documentation on clock() says that it should return clock ticks since program started, which with the 15
second sleep that should be plenty. I don''t understand.



#include <ctime>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
sleep(10);
cout << clock() << endl;
return 0;
}
Outputs "15".



JetSnaiL wrote:

ro**********@gmail.comwrote:


Ok, so I am trying to establish how boost.timer works and I try a
few

things and afaict it doesn''t. So I open the header to see why and


run

some tests to establish what is going on and it all boils down to


the

clock() function. Here is the code:
#include <iostream>
#include <cstdlib>

int main(void)
{
boost::timer tmr;
sleep(15);

std::cout << std::clock() << std::endl;

return 0;
}
That program always outputs "0". Documentation on clock() says that


it

should return clock ticks since program started, which with the 15
second sleep that should be plenty. I don''t understand.



#include <ctime>
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
sleep(10);
cout << clock() << endl;
return 0;
}
Outputs "15".



Well, I get 0.


这篇关于时钟()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆