diff --git a/dygraph/deploy/cpp/src/object_detector.cc b/dygraph/deploy/cpp/src/object_detector.cc index f629acd8ce0ad4b77b0fd85d6280c8528d876d68..969425dcedc1ec532951d7919aff215026a423ff 100644 --- a/dygraph/deploy/cpp/src/object_detector.cc +++ b/dygraph/deploy/cpp/src/object_detector.cc @@ -14,6 +14,7 @@ #include // for setprecision #include +#include #include "include/object_detector.h" @@ -230,7 +231,7 @@ void ObjectDetector::Predict(const cv::Mat& im, out_tensor->CopyToCpu(output_data_.data()); } - std::clock_t start = clock(); + auto start = std::chrono::steady_clock::now(); for (int i = 0; i < repeats; i++) { predictor_->Run(); @@ -250,8 +251,9 @@ void ObjectDetector::Predict(const cv::Mat& im, output_data_.resize(output_size); out_tensor->CopyToCpu(output_data_.data()); } - std::clock_t end = clock(); - float ms = static_cast(end - start) / CLOCKS_PER_SEC / repeats * 1000.; + auto end = std::chrono::steady_clock::now(); + std::chrono::duration diff = end - start; + float ms = diff.count() / repeats * 1000; printf("Inference: %f ms per batch image\n", ms); // Postprocessing result if(!run_benchmark) { diff --git a/static/deploy/cpp/src/object_detector.cc b/static/deploy/cpp/src/object_detector.cc index 2b18de3bbe242b87821be5b2c9b4307c9914f12f..0e5b814eb0f9cec1c557cc5ce666f9b171a8fdcb 100644 --- a/static/deploy/cpp/src/object_detector.cc +++ b/static/deploy/cpp/src/object_detector.cc @@ -14,6 +14,7 @@ #include // for setprecision #include +#include #include "include/object_detector.h" namespace PaddleDetection { @@ -207,7 +208,7 @@ void ObjectDetector::Predict(const cv::Mat& im, out_tensor->copy_to_cpu(output_data_.data()); } - std::clock_t start = clock(); + auto start = std::chrono::steady_clock::now(); for (int i = 0; i < repeats; i++) { predictor_->ZeroCopyRun(); @@ -227,8 +228,9 @@ void ObjectDetector::Predict(const cv::Mat& im, output_data_.resize(output_size); out_tensor->copy_to_cpu(output_data_.data()); } - std::clock_t end = clock(); - float ms = static_cast(end - start) / CLOCKS_PER_SEC / repeats * 1000.; + auto end = std::chrono::steady_clock::now(); + std::chrono::duration diff = end - start; + float ms = diff.count() / repeats * 1000; printf("Inference: %f ms per batch image\n", ms); // Postprocessing result if(!run_benchmark) {