test: Measure inference performance
authorInki Dae <inki.dae@samsung.com>
Thu, 27 Feb 2020 04:19:26 +0000 (13:19 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 14 Apr 2020 00:42:19 +0000 (09:42 +0900)
Change-Id: I217ac9b61890757a0f073007f95703f69e341209
Signed-off-by: Inki Dae <inki.dae@samsung.com>
test/testsuites/inference/inference_test_suite.c

index 9a27c366cf91b7f2dac826b8a31c095602bbee2a..717fe0d6956b647f375266122cbcc24740916145 100644 (file)
@@ -29,6 +29,7 @@
 #include <dirent.h>
 #include <string.h>
 #include <limits.h>
+#include <time.h>
 
 #define FILE_PATH_SIZE 1024
 
  *      Ps. media vision supports cpm and hourglass models for pose estimaion for now.
  */
 
+#define NANO_PER_SEC ((__clock_t) 1000000000)
+#define NANO_PER_MILLI  ((__clock_t) 1000000)
+#define MILLI_PER_SEC  ((__clock_t) 1000)
+
+struct timespec diff(struct timespec start, struct timespec end)
+{
+    struct timespec temp;
+    if ((end.tv_nsec - start.tv_nsec) < 0) {
+        temp.tv_sec = end.tv_sec - start.tv_sec - 1;
+        temp.tv_nsec = NANO_PER_SEC + end.tv_nsec - start.tv_nsec;
+    }
+    else {
+        temp.tv_sec = end.tv_sec - start.tv_sec;
+        temp.tv_nsec = end.tv_nsec - start.tv_nsec;
+    }
+    return temp;
+}
+
+unsigned long gettotalmillisec(const struct timespec time)
+{
+    return time.tv_sec * MILLI_PER_SEC + time.tv_nsec / NANO_PER_MILLI;
+}
+
 void _object_detected_cb (
         mv_source_h source,
         const int number_of_objects,
@@ -875,8 +899,20 @@ int perform_image_classification()
             }
             free(in_file_name);
 
+            struct timespec s_tspec;
+            struct timespec e_tspec;
+
+            clock_gettime(CLOCK_MONOTONIC, &s_tspec);
+
             // Run
             err = mv_inference_image_classify(mvSource, infer, NULL, _image_classified_cb, NULL);
+
+            clock_gettime(CLOCK_MONOTONIC, &e_tspec);
+
+            struct timespec diffspec = diff(s_tspec, e_tspec);
+            unsigned long timeDiff = gettotalmillisec(diffspec);
+            printf("elased time : %lu(ms)\n", timeDiff);
+
         }
             break;
         case 7:
@@ -1239,8 +1275,20 @@ int perform_object_detection()
             }
             free(in_file_name);
 
+            struct timespec s_tspec;
+            struct timespec e_tspec;
+
+            clock_gettime(CLOCK_MONOTONIC, &s_tspec);
+
             // Object Detect
             err = mv_inference_object_detect(mvSource, infer, _object_detected_cb, NULL);
+
+            clock_gettime(CLOCK_MONOTONIC, &e_tspec);
+
+            struct timespec diffspec = diff(s_tspec, e_tspec);
+            unsigned long timeDiff = gettotalmillisec(diffspec);
+            printf("elased time : %lu(ms)\n", timeDiff);
+
         }
             break;
         case 6:
@@ -1592,8 +1640,19 @@ int perform_face_detection()
             }
             free(in_file_name);
 
+            struct timespec s_tspec;
+            struct timespec e_tspec;
+
+            clock_gettime(CLOCK_MONOTONIC, &s_tspec);
+
             // Object Detect
             err = mv_inference_face_detect(mvSource, infer, _face_detected_cb, NULL);
+
+            clock_gettime(CLOCK_MONOTONIC, &e_tspec);
+
+            struct timespec diffspec = diff(s_tspec, e_tspec);
+            unsigned long timeDiff = gettotalmillisec(diffspec);
+            printf("elased time : %lu(ms)\n", timeDiff);
         }
             break;
         case 6:
@@ -1852,8 +1911,19 @@ int perform_facial_landmark_detection()
             }
             free(in_file_name);
 
+            struct timespec s_tspec;
+            struct timespec e_tspec;
+
+            clock_gettime(CLOCK_MONOTONIC, &s_tspec);
+
             // Object Detect
             err = mv_inference_facial_landmark_detect(mvSource, infer, NULL, _facial_landmark_detected_cb, NULL);
+
+            clock_gettime(CLOCK_MONOTONIC, &e_tspec);
+
+            struct timespec diffspec = diff(s_tspec, e_tspec);
+            unsigned long timeDiff = gettotalmillisec(diffspec);
+            printf("elased time : %lu(ms)\n", timeDiff);
         }
             break;
         case 5:
@@ -2109,8 +2179,20 @@ int perform_pose_estimation_detection()
             }
             free(in_file_name);
 
+            struct timespec s_tspec;
+            struct timespec e_tspec;
+
+            clock_gettime(CLOCK_MONOTONIC, &s_tspec);
+
             // Pose estimation
             err = mv_inference_pose_estimation_detect(mvSource, infer, NULL, _pose_estimation_detected_cb, NULL);
+
+            clock_gettime(CLOCK_MONOTONIC, &e_tspec);
+
+            struct timespec diffspec = diff(s_tspec, e_tspec);
+            unsigned long timeDiff = gettotalmillisec(diffspec);
+            printf("elased time : %lu(ms)\n", timeDiff);
+
             break;
         }
         case 5: