!30342 Use steady_clock() instead of gettimeofday() for profiling

Merge pull request !30342 from hewei/opt_perf
This commit is contained in:
i-robot 2022-02-22 02:00:34 +00:00 committed by Gitee
commit a2bf3f522c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 4 additions and 13 deletions

View File

@ -15,12 +15,7 @@
*/
#include "utils/profile.h"
#ifdef _MSC_VER
#include <time.h>
#else
#include <sys/time.h>
#include <unistd.h>
#endif
#include <chrono>
#include <numeric>
#include <cstdio>
#include <sstream>
@ -123,13 +118,9 @@ void PrintProfile(std::ostringstream &oss, const TimeInfo &time_info, int indent
} // namespace
double GetTime(void) {
#ifdef _MSC_VER
return time(NULL);
#else
struct timeval tv = {0, 0};
(void)gettimeofday(&tv, nullptr);
return tv.tv_sec + tv.tv_usec * 1.0e-6;
#endif
auto now = std::chrono::steady_clock::now();
std::chrono::duration<double> d = now.time_since_epoch();
return d.count();
}
TimeInfo::~TimeInfo() {