想要度量和验证实时系统中的响应时间,请使用以下宏:
| 名称 | 详情 |
|---|---|
CppTest_Time CppTest_TimeInit(CPPTEST_INTEGER seconds, CPPTEST_INTEGER nanoseconds); | 使用给定的值初始化CppTest_Time结构。纳秒应在 -999999999 和 999999999 之间 |
CppTest_Time CppTest_TimeCurrent(); | 用当前时间初始化 时间以 1970 年 01 月 01 日世界标准时间 00:00:00 以来的秒数(和纳秒)存储。 准确性取决于所使用的平台。 |
CppTest_Time CppTest_TimeDiff(CppTest_Time t1, CppTest_Time t2); | 返回t1和t2之间的差。 |
int CppTest_TimeCompare(CppTest_Time t1, CppTest_Time t2); | 比较两个 返回:
|
这是一个如何使用这些宏来度量和报告时间的示例:
...
/* Collect start time */
CppTest_Time start = CppTest_TimeCurrent();
/* Tested function call */
int _return = ::foo();
/* Compute time diff */
CppTest_Time stop = CppTest_TimeCurrent();
CppTest_Time diff = CppTest_TimeDiff(stop, start);
/* Report time diff (assuming positive values) */
CPPTEST_MESSAGE(cpptestFormat("Call time for foo(): %d.%09d", diff.seconds, diff.nanoseconds));
...
这是有关如何使用这些宏检查和比较时间的示例:
... /* Verify execution time */ CppTest_Time limit5ms = CppTest_TimeInit(0, 5000000); CPPTEST_ASSERT(CppTest_TimeCompare(diff, limit5ms) < 0) ...