比较时间规范值
Comparing timespec values
比较两个时间规范值以查看哪个先发生的最佳方法是什么?
以下有什么问题吗?
bool BThenA(timespec a, timespec b) {
//Returns true if b happened first -- b will be "lower".
if (a.tv_sec == b.tv_sec)
return a.tv_nsec > b.tv_nsec;
else
return a.tv_sec > b.tv_sec;
}
另一种方法是为timespec
定义全局operator <()
。 然后你可以比较一下,如果一个时间发生在另一个时间之前。
bool operator <(const timespec& lhs, const timespec& rhs)
{
if (lhs.tv_sec == rhs.tv_sec)
return lhs.tv_nsec < rhs.tv_nsec;
else
return lhs.tv_sec < rhs.tv_sec;
}
然后在你的代码中你可以有
timespec start, end;
//get start and end populated
if (start < end)
cout << "start is smaller";
相关文章:
- 具有未知值时的时间复杂性
- 我的固定时间步长与增量时间和插值的解决方案是错误的吗?
- 如何在 for 循环中的特定时间内获取要打印的额外值
- 如何优化C++键值程序以获得更快的运行时间
- 注册表-获取值(而不是键)上次更改的时间和键创建日期
- 重复值的最长运行时间
- 为什么时间测量有时会返回重复值(15.625ms 的倍数)?
- 添加两个时间值存储为数据库中的字符串
- 通过引用传递基元类型(如 int、bool)是否比按值传递有任何加速?还是会恶化时间/空间的使用
- 如何检查 O(N) 时间复杂度的多重集中是否有 2 个或更多元素具有相同的值
- 如何恢复注册表项的所有元素?(上次写入时间,类型,值,名称...这是正确的方法吗?
- 使用变量通过参考和C 中的值传递的时间
- C 数组值分配时间
- 可传递值影响递归算法的渐近时间复杂性
- 将当前时间 simTime.dbl() 与以前存储的双精度值进行比较并不总是给出正确的答案......为什么?
- 难以找到向量的最小时间值
- C++ 时间存储time_point表达式必须是可修改的左值
- 添加时间戳值
- C ++中的最大值和最小值时间复杂度O
- 使用 spirit 将日期时间字符串解析为time_t值