diff --git a/samples/gpu/performance/performance.cpp b/samples/gpu/performance/performance.cpp index 1b5a0bf8c5..03e00654f0 100644 --- a/samples/gpu/performance/performance.cpp +++ b/samples/gpu/performance/performance.cpp @@ -33,9 +33,8 @@ void TestSystem::run() } cout << setiosflags(ios_base::fixed | ios_base::left); - cout << "\nCPU Total: " << setprecision(3) << cpu_total_ / getTickFrequency() << " sec\n"; - cout << "GPU Total: " << setprecision(3) << gpu_total_ / getTickFrequency() << " sec (x" - << setprecision(3) << static_cast(cpu_total_) / gpu_total_ << ")\n"; + cout << "\nAverage GPU Speedup: x" << setprecision(3) + << speedup_total_ / num_subtests_called_ << endl; cout << resetiosflags(ios_base::fixed | ios_base::left); } @@ -47,7 +46,9 @@ void TestSystem::flush() int cpu_time = static_cast(cpu_elapsed_ / getTickFrequency() * 1000.0); int gpu_time = static_cast(gpu_elapsed_ / getTickFrequency() * 1000.0); + double speedup = static_cast(cpu_time) / gpu_time; + speedup_total_ += speedup; cpu_elapsed_ = 0; gpu_elapsed_ = 0; @@ -72,6 +73,7 @@ void TestSystem::flush() cout << resetiosflags(ios_base::fixed | ios_base::left) << endl; can_flush_ = false; + num_subtests_called_++; } diff --git a/samples/gpu/performance/performance.h b/samples/gpu/performance/performance.h index 354c54e411..8fbe667f28 100644 --- a/samples/gpu/performance/performance.h +++ b/samples/gpu/performance/performance.h @@ -42,7 +42,6 @@ public: { int64 delta = cv::getTickCount() - cpu_started_; cpu_elapsed_ += delta; - cpu_total_ += delta; can_flush_ = true; } @@ -52,7 +51,6 @@ public: { int64 delta = cv::getTickCount() - gpu_started_; gpu_elapsed_ += delta; - gpu_total_ += delta; can_flush_ = true; } @@ -64,9 +62,8 @@ public: } private: - TestSystem(): can_flush_(false), - cpu_elapsed_(0), cpu_total_(0), - gpu_elapsed_(0), gpu_total_(0) {}; + TestSystem(): can_flush_(false), cpu_elapsed_(0), gpu_elapsed_(0), + speedup_total_(0.0), num_subtests_called_(0) {}; void flush(); @@ -77,8 +74,11 @@ private: bool can_flush_; - int64 cpu_started_, cpu_elapsed_, cpu_total_; - int64 gpu_started_, gpu_elapsed_, gpu_total_; + int64 cpu_started_, cpu_elapsed_; + int64 gpu_started_, gpu_elapsed_; + + double speedup_total_; + int num_subtests_called_; }; diff --git a/samples/gpu/performance/tests.cpp b/samples/gpu/performance/tests.cpp index bd4957fd9b..db31237c22 100644 --- a/samples/gpu/performance/tests.cpp +++ b/samples/gpu/performance/tests.cpp @@ -7,24 +7,52 @@ using namespace cv; TEST(matchTemplate) { + Mat image, templ, result; + gen(image, 3000, 3000, CV_8U); + + gpu::GpuMat d_image(image), d_templ, d_result; + for (int templ_size = 5; templ_size <= 1000; templ_size *= 2) { SUBTEST << "img 3000, templ " << templ_size << ", 8U, SQDIFF"; - Mat image; gen(image, 3000, 3000, CV_8U); - Mat templ; gen(templ, templ_size, templ_size, CV_8U); - Mat result; + gen(templ, templ_size, templ_size, CV_8U); CPU_ON; matchTemplate(image, templ, result, CV_TM_SQDIFF); CPU_OFF; - gpu::GpuMat d_image(image); - gpu::GpuMat d_templ(templ); - gpu::GpuMat d_result; + d_templ = templ; GPU_ON; gpu::matchTemplate(d_image, d_templ, d_result, CV_TM_SQDIFF); GPU_OFF; } } + + +TEST(minMaxLoc) +{ + Mat src; + gpu::GpuMat d_src; + + double min_val, max_val; + Point min_loc, max_loc; + + for (int size = 2000; size <= 8000; size *= 2) + { + SUBTEST << "img " << size << ", 32F, no mask"; + + gen(src, size, size, CV_32F); + + CPU_ON; + minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc); + CPU_OFF; + + d_src = src; + + GPU_ON; + gpu::minMaxLoc(d_src, &min_val, &max_val, &min_loc, &max_loc); + GPU_OFF; + } +} \ No newline at end of file