c++ - C++中time_t和time_point的使用效率

标签 c++ datetime processing-efficiency memory-efficient

在 C++ 中,std::time_t 和 std::chrono::time_point 是用于存储日期和时间的类。使用 time_point 存储时间是否有效。貌似time_point支持的功能比较多,使用起来效率会不会比time_t低? time_point 实例的内存大小大约有多大? time_t 实例的大小是多少?

最佳答案

Is it efficient to use time_point to store the time.

是的,它只包含一个数值。

It seems that time_point supports more functions, will it be less efficient while using it compared with time_t?

为什么会这样想?非虚函数不会增加对象大小,应该内联简单的函数,这样它们就可以像直接乱用数值一样高效。

About how large in memory size is an instance of time_point?

与您告诉它使用的数字类型大小相同。如果您使用一种方便的持续时间类型(如 seconds),则可能是 64 位。检查 sizeof 是否重要。

What's the size of instance of time_t?

未指定,通常为 32 或 64 位。如果重要,请检查 sizeof。如果它是 32,那么您可能会在几十年后遇到麻烦。

关于c++ - C++中time_t和time_point的使用效率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28982544/

相关文章:

c++ - 如何防止使用尚未构造的类成员?

python - Selenium python 中的日期时间抛出错误

安卓 DatePicker- GregorianCalendar-00 :00:00 UTC - getTimeInMillis()

performance - Erlang 'catch'表达式与try/catch在效率方面的关系

php - 执行此 PHP 脚本的最有效方法

c++ - 如何使用 strip 化算法读取 residence.dat 文件 C++

c++ - 在 Windows 上调试 linux 故障转储

r - 如何在 R 中优化 sapply 以计算数据帧上的运行总计

c++ - GCC的两个异常错误信息

c# - 以微秒为单位的日期时间