From ef144953f4fc8342c46757e66d88f3b9f2c7b86c Mon Sep 17 00:00:00 2001 From: Zhen Wang Date: Wed, 12 Oct 2022 10:49:48 +0800 Subject: [PATCH] Fix some timing errors. (#46886) --- paddle/infrt/tests/timer.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/paddle/infrt/tests/timer.h b/paddle/infrt/tests/timer.h index cfd382d456c..f08fa15338b 100644 --- a/paddle/infrt/tests/timer.h +++ b/paddle/infrt/tests/timer.h @@ -16,6 +16,9 @@ #include #include +#include +#include +#include namespace infrt { namespace tests { @@ -40,7 +43,12 @@ class ChronoTimer { TimePoint start_; }; -using WallClockTimer = ChronoTimer; +// To learn more about the difference between system_clock and steady_clock, +// please refer to https://www.cnblogs.com/zhongpan/p/7490657.html. +// To learn more about the difference between Wall Time and CPU Time, +// please refer to https://blog.csdn.net/aganlengzi/article/details/21888351 +// and https://blog.csdn.net/filyouzicha/article/details/52447887. +using WallClockTimer = ChronoTimer; class CpuClockTimer { public: @@ -73,8 +81,10 @@ class BenchmarkStats { std::sort(wall_time_.begin(), wall_time_.end()); std::sort(cpu_time_.begin(), cpu_time_.end()); auto percentile = [](float p, const std::vector& stats) { - assert(p >= 0 && p < 1); - return stats[stats.size() * p]; + size_t mark = stats.size() * p; + mark = std::max(mark, static_cast(0)); + mark = std::min(mark, stats.size() - 1); + return stats[mark]; }; for (auto p : percents) { ss << "=== Wall Time (ms): \n"; -- GitLab