diff options
author | Inki Dae <inki.dae@samsung.com> | 2018-01-04 10:32:16 +0900 |
---|---|---|
committer | Inki Dae <inki.dae@samsung.com> | 2018-10-08 15:17:35 +0900 |
commit | b85b8637c52f1c89ab8d4c7e6d9ba2e48d0bd9e8 (patch) | |
tree | b1773f65839a247fda395fe586b2010af75bde4f | |
parent | 44889f598c73a2d05c7e123fdee3b5854a17c4fb (diff) | |
download | caffeonacl-b85b8637c52f1c89ab8d4c7e6d9ba2e48d0bd9e8.tar.gz caffeonacl-b85b8637c52f1c89ab8d4c7e6d9ba2e48d0bd9e8.tar.bz2 caffeonacl-b85b8637c52f1c89ab8d4c7e6d9ba2e48d0bd9e8.zip |
examples: measure performance of inference
Signed-off-by: Inki Dae <inki.dae@samsung.com>
-rw-r--r-- | examples/cpp_classification/classification_profiling.cpp | 23 | ||||
-rw-r--r-- | examples/cpp_classification/classification_profiling_gpu.cpp | 23 |
2 files changed, 34 insertions, 12 deletions
diff --git a/examples/cpp_classification/classification_profiling.cpp b/examples/cpp_classification/classification_profiling.cpp index f5d5eaed..50afe181 100644 --- a/examples/cpp_classification/classification_profiling.cpp +++ b/examples/cpp_classification/classification_profiling.cpp @@ -530,13 +530,24 @@ int main(int argc, char** argv) { cv::Mat img = cv::imread(file, -1); CHECK(!img.empty()) << "Unable to decode image " << file; - std::vector<Prediction> predictions = classifier.Classify(img); - /* Print the top N predictions. */ - for (size_t i = 0; i < predictions.size(); ++i) { - Prediction p = predictions[i]; - std::cout << std::fixed << std::setprecision(4) << p.second << " - \"" - << p.first << "\"" << std::endl; + struct timeval t1, t2; + + for (int i = 0; i < 5; i++) { + gettimeofday(&t1, NULL); + std::vector<Prediction> predictions = classifier.Classify(img); + gettimeofday(&t2, NULL); + + /* Print the top N predictions. */ + for (size_t i = 0; i < predictions.size(); ++i) { + Prediction p = predictions[i]; + std::cout << std::fixed << std::setprecision(4) << p.second << " - \"" + << p.first << "\"" << std::endl; + } + + double elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; + elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms + std::cout << elapsedTime << " ms.\n"; } } #else diff --git a/examples/cpp_classification/classification_profiling_gpu.cpp b/examples/cpp_classification/classification_profiling_gpu.cpp index 3c5e04ad..2854415d 100644 --- a/examples/cpp_classification/classification_profiling_gpu.cpp +++ b/examples/cpp_classification/classification_profiling_gpu.cpp @@ -530,13 +530,24 @@ int main(int argc, char** argv) { cv::Mat img = cv::imread(file, -1); CHECK(!img.empty()) << "Unable to decode image " << file; - std::vector<Prediction> predictions = classifier.Classify(img); - /* Print the top N predictions. */ - for (size_t i = 0; i < predictions.size(); ++i) { - Prediction p = predictions[i]; - std::cout << std::fixed << std::setprecision(4) << p.second << " - \"" - << p.first << "\"" << std::endl; + struct timeval t1, t2; + + for (int i = 0; i < 5; i++) { + gettimeofday(&t1, NULL); + std::vector<Prediction> predictions = classifier.Classify(img); + gettimeofday(&t2, NULL); + + /* Print the top N predictions. */ + for (size_t i = 0; i < predictions.size(); ++i) { + Prediction p = predictions[i]; + std::cout << std::fixed << std::setprecision(4) << p.second << " - \"" + << p.first << "\"" << std::endl; + } + + double elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; + elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms + std::cout << elapsedTime << " ms.\n"; } } #else |