[nnpkg_run] use chrono to measure time (#6858)
authorVladimir Plazun/AI Tools Lab /SRR/Engineer/삼성전자 <v.plazun@samsung.com>
Mon, 26 Aug 2019 18:51:53 +0000 (21:51 +0300)
committerAlexander Efimov/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Mon, 26 Aug 2019 18:51:53 +0000 (21:51 +0300)
Use c++ chrono instead of linux's gettimeofday

Signed-off-by: Vladimir Plazun <v.plazun@samsung.com>
tests/tools/nnpackage_run/src/nnpackage_run.cc

index dce5dbd..97edebf 100644 (file)
@@ -22,7 +22,8 @@
 
 #include <assert.h>
 #include <iostream>
-#include <sys/time.h>
+
+#include <chrono>
 
 #define NNPR_ENSURE_STATUS(a)        \
   do                                 \
 
 uint64_t NowMicros()
 {
-  struct timeval tv;
-  gettimeofday(&tv, nullptr);
-  return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
+  auto time_point = std::chrono::high_resolution_clock::now();
+  auto since_epoch = time_point.time_since_epoch();
+  // default precision of high resolution clock is 10e-9 (nanoseconds)
+  return std::chrono::duration_cast<std::chrono::microseconds>(since_epoch).count();
 }
 
 uint64_t num_elems(const nnfw_tensorinfo *ti)