forked from mindspore-Ecosystem/mindspore
!30342 Use steady_clock() instead of gettimeofday() for profiling
Merge pull request !30342 from hewei/opt_perf
This commit is contained in:
commit
a2bf3f522c
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue