未验证 提交 6716d44c 编写于 作者: Z zlsh80826 提交者: GitHub

Time measurement API (#2401)

* replace clock by chrono for accurate elapsed time

* replace clock by chrono for accurate elapsed time in dygraph
上级 df63725b
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sstream> #include <sstream>
// for setprecision // for setprecision
#include <iomanip> #include <iomanip>
#include <chrono>
#include "include/object_detector.h" #include "include/object_detector.h"
...@@ -230,7 +231,7 @@ void ObjectDetector::Predict(const cv::Mat& im, ...@@ -230,7 +231,7 @@ void ObjectDetector::Predict(const cv::Mat& im,
out_tensor->CopyToCpu(output_data_.data()); 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++) for (int i = 0; i < repeats; i++)
{ {
predictor_->Run(); predictor_->Run();
...@@ -250,8 +251,9 @@ void ObjectDetector::Predict(const cv::Mat& im, ...@@ -250,8 +251,9 @@ void ObjectDetector::Predict(const cv::Mat& im,
output_data_.resize(output_size); output_data_.resize(output_size);
out_tensor->CopyToCpu(output_data_.data()); out_tensor->CopyToCpu(output_data_.data());
} }
std::clock_t end = clock(); auto end = std::chrono::steady_clock::now();
float ms = static_cast<float>(end - start) / CLOCKS_PER_SEC / repeats * 1000.; std::chrono::duration<float> diff = end - start;
float ms = diff.count() / repeats * 1000;
printf("Inference: %f ms per batch image\n", ms); printf("Inference: %f ms per batch image\n", ms);
// Postprocessing result // Postprocessing result
if(!run_benchmark) { if(!run_benchmark) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <sstream> #include <sstream>
// for setprecision // for setprecision
#include <iomanip> #include <iomanip>
#include <chrono>
#include "include/object_detector.h" #include "include/object_detector.h"
namespace PaddleDetection { namespace PaddleDetection {
...@@ -207,7 +208,7 @@ void ObjectDetector::Predict(const cv::Mat& im, ...@@ -207,7 +208,7 @@ void ObjectDetector::Predict(const cv::Mat& im,
out_tensor->copy_to_cpu(output_data_.data()); 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++) for (int i = 0; i < repeats; i++)
{ {
predictor_->ZeroCopyRun(); predictor_->ZeroCopyRun();
...@@ -227,8 +228,9 @@ void ObjectDetector::Predict(const cv::Mat& im, ...@@ -227,8 +228,9 @@ void ObjectDetector::Predict(const cv::Mat& im,
output_data_.resize(output_size); output_data_.resize(output_size);
out_tensor->copy_to_cpu(output_data_.data()); out_tensor->copy_to_cpu(output_data_.data());
} }
std::clock_t end = clock(); auto end = std::chrono::steady_clock::now();
float ms = static_cast<float>(end - start) / CLOCKS_PER_SEC / repeats * 1000.; std::chrono::duration<float> diff = end - start;
float ms = diff.count() / repeats * 1000;
printf("Inference: %f ms per batch image\n", ms); printf("Inference: %f ms per batch image\n", ms);
// Postprocessing result // Postprocessing result
if(!run_benchmark) { if(!run_benchmark) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册