如何使用ctime来标记程序的起点和终点
How to use ctime to mark starting and ending point of the program?
time_t start;
time_t no_infection;
bool time_already_set = 0;
bool infected_or_not = 0;
int not_infected_t = 0;
我在结构中有这个变量,我想标记对象的起点和终点,而不是计算差值。
void bacteria::set_no_infection() {
if (infected_or_not == 0)
no_infection = clock();
}
首先我有
void bacteria::set_time() {
if (infected_or_not == 1 && time_already_set!=1) {
start = clock();
time_already_set = 1;
}
}
在程序中,时间变量似乎没有变化。我使用get函数对其进行了测试
double bacteria::get_time() {
if (infected_or_not == 1)
return ((clock() - start) / CLOCKS_PER_SEC);
else
return -1;
}
int bacteria::get_no_infection() {
if (infected_or_not = 0)
return ((clock() - no_infection) / CLOCKS_PER_SEC);
else
return -1;
}
在主程序中,我这样测试它:
while (1) {
for (int i = 0; i < b.size() - 1; i++) {
bactpop[i].set_no_infection();
bactpop[i].inf(phagepop[i], bactpop[i], p);
bactpop[i].kill_the_bacteria(b, i);
cout << " " << b[i].start << " " << b[i].no_infection << endl;
}
cout << p.size() << " " << b.size() << endl;
}
我不确定,但我猜您的函数每秒被调用几次,由于clock((/CLOCKS_per_SEC以秒为单位返回值,因此差异将为0,因为调用是在同一秒内执行的。
例如,如果可以使用C++11,则使用gettimeofday(以微秒为单位(或std::chrono::high_resolution_clock::now((。
相关文章:
- 是否可以在 OpenGL 中的同一调用中呈现两个具有不同索引起点的不同缓冲区?
- 定义/预设NURBS起点和终点的方向
- 如何设置QTreeView的起点目录?
- 如何在opengl中绘制具有给定起点的弧线?
- 如何调用具有不同字符串起点的函数?
- 没有htonl/ntohl的联盟和终点
- 从卷或区域中的起点向外迭代,而不对其进行排序
- 警告:控制可能达到非无效功能的终点?返课时
- 如何在给定起点和终点的字符串中查找子字符串的出现次数?
- 给定许多垂直或水平段及其终点的坐标(x1,x2,y1,y2),我们有多少个相交
- 控制达到非空隙功能的终点,C++
- 从一个起点遍历一个图形,并在起点C++处结束
- 牡丹SSL/TLS示例或起点
- ld:入口点(起点)未定义.通常在crt1.o中用于体系结构x86_64
- 起点和终点固定的多目的地最短路线
- 在.pdf中找到终点线
- 在三维中从起点和角度计算一条线
- 如何从一组边的起点和终点构造多边形?
- 定义为起点和长度+方向的线与定义为起点和终点的线不同-方向计算错误
- 如何使用ctime来标记程序的起点和终点