[tflite_benchmark] Insert pause between iterations (#6189)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 5 Aug 2019 03:53:13 +0000 (12:53 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 5 Aug 2019 03:53:13 +0000 (12:53 +0900)
tflite_benchmark now allows users to insert pause between iterations via
"PAUSE" environment variable.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
tests/tools/tflite_benchmark/src/tflite_benchmark.cc

index 27ef2cb..54c97c4 100644 (file)
@@ -30,7 +30,9 @@
 #include <boost/accumulators/statistics/max.hpp>
 #include <boost/accumulators/statistics/mean.hpp>
 
+#include <chrono>
 #include <iostream>
+#include <thread>
 
 #include "misc/environment.h"
 #include "misc/benchmark.h"
@@ -70,6 +72,7 @@ int main(const int argc, char **argv)
 
   const bool use_nnapi = nnfw::misc::get_env_bool("USE_NNAPI");
   const auto thread_count = nnfw::misc::get_env_int("THREAD", -1);
+  const auto pause = nnfw::misc::get_env_int("PAUSE", 0);
 
   std::cout << "Num threads: " << thread_count << std::endl;
   if (use_nnapi)
@@ -77,6 +80,12 @@ int main(const int argc, char **argv)
     std::cout << "Use NNAPI" << std::endl;
   }
 
+  assert(pause >= 0);
+  if (pause > 0)
+  {
+    std::cout << "Insert " << pause << "s pause between iterations" << std::endl;
+  }
+
   StderrReporter error_reporter;
 
   auto model = FlatBufferModel::BuildFromFile(filename, &error_reporter);
@@ -228,6 +237,12 @@ int main(const int argc, char **argv)
     acc(elapsed.count());
 
     std::cout << "Iteration " << n << ": " << elapsed.count() << "ms" << std::endl;
+
+    // Insert "pause"
+    if ((n != cnt - 1) && (pause > 0))
+    {
+      std::this_thread::sleep_for(std::chrono::seconds(pause));
+    }
   }
 
   std::cout << "--------" << std::endl;