要度量和验证实时系统中的响应时间,可使用以下宏:
名称 | 详情 |
---|---|
CppTest_Time CppTest_TimeInit(CPPTEST_INTEGER seconds, CPPTEST_INTEGER nanoseconds); | 使用给定的值初始化 CppTest_Time 结构体。纳秒值应位于 -999999999 和 999999999 之间 |
CppTest_Time CppTest_TimeCurrent(); | 使用当前时间初始化 时间以自 1970 年 1 月 1 日 00:00:00 UTC 起的秒数(和纳秒数)存储。 准确性取决于所使用的平台。 |
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) ...