From 214e9d4b12c65a406ec5b6a8e21214079535427b Mon Sep 17 00:00:00 2001 From: Max Khardin Date: Sat, 4 Jan 2014 18:56:32 +0800 Subject: [PATCH 1/4] Add performance tests for elementwise multiplication --- modules/core/perf/perf_arithm.cpp | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/modules/core/perf/perf_arithm.cpp b/modules/core/perf/perf_arithm.cpp index 22d7def2c9..72fd21970a 100644 --- a/modules/core/perf/perf_arithm.cpp +++ b/modules/core/perf/perf_arithm.cpp @@ -202,3 +202,49 @@ PERF_TEST_P(Size_MatType, subtractScalar, TYPICAL_MATS_CORE_ARITHM) SANITY_CHECK(c, 1e-8); } + + +PERF_TEST_P(Size_MatType, multiply, TYPICAL_MATS_CORE_ARITHM) +{ + Size sz = get<0>(GetParam()); + int type = get<1>(GetParam()); + cv::Mat a = Mat(sz, type); + cv::Mat b = Mat(sz, type); + cv::Mat c = Mat(sz, type); + + declare.in(a, b, WARMUP_RNG).out(c); + + if (CV_MAT_DEPTH(type) == CV_32S) + { + //According to docs, saturation is not applied when result is 32bit integer + a /= (2 << 16); + b /= (2 << 16); + } + + TEST_CYCLE() multiply(a, b, c); + + SANITY_CHECK(c, 1e-8); +} + +PERF_TEST_P(Size_MatType, multiplyScale, TYPICAL_MATS_CORE_ARITHM) +{ + Size sz = get<0>(GetParam()); + int type = get<1>(GetParam()); + cv::Mat a = Mat(sz, type); + cv::Mat b = Mat(sz, type); + cv::Mat c = Mat(sz, type); + double scale = 0.5; + + declare.in(a, b, WARMUP_RNG).out(c); + + if (CV_MAT_DEPTH(type) == CV_32S) + { + //According to docs, saturation is not applied when result is 32bit integer + a /= (2 << 16); + b /= (2 << 16); + } + + TEST_CYCLE() multiply(a, b, c, scale); + + SANITY_CHECK(c, 1e-8); +} From 34b05794d60e9f7043f652a55a4ad250b22a2dac Mon Sep 17 00:00:00 2001 From: Max Khardin Date: Sat, 4 Jan 2014 19:01:32 +0800 Subject: [PATCH 2/4] Fix source code indents --- modules/core/perf/perf_arithm.cpp | 60 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/modules/core/perf/perf_arithm.cpp b/modules/core/perf/perf_arithm.cpp index 72fd21970a..977a70e0de 100644 --- a/modules/core/perf/perf_arithm.cpp +++ b/modules/core/perf/perf_arithm.cpp @@ -203,48 +203,46 @@ PERF_TEST_P(Size_MatType, subtractScalar, TYPICAL_MATS_CORE_ARITHM) SANITY_CHECK(c, 1e-8); } - PERF_TEST_P(Size_MatType, multiply, TYPICAL_MATS_CORE_ARITHM) { - Size sz = get<0>(GetParam()); - int type = get<1>(GetParam()); - cv::Mat a = Mat(sz, type); - cv::Mat b = Mat(sz, type); - cv::Mat c = Mat(sz, type); + Size sz = get<0>(GetParam()); + int type = get<1>(GetParam()); + cv::Mat a = Mat(sz, type); + cv::Mat b = Mat(sz, type); + cv::Mat c = Mat(sz, type); - declare.in(a, b, WARMUP_RNG).out(c); + declare.in(a, b, WARMUP_RNG).out(c); + if (CV_MAT_DEPTH(type) == CV_32S) + { + //According to docs, saturation is not applied when result is 32bit integer + a /= (2 << 16); + b /= (2 << 16); + } - if (CV_MAT_DEPTH(type) == CV_32S) - { - //According to docs, saturation is not applied when result is 32bit integer - a /= (2 << 16); - b /= (2 << 16); - } + TEST_CYCLE() multiply(a, b, c); - TEST_CYCLE() multiply(a, b, c); - - SANITY_CHECK(c, 1e-8); + SANITY_CHECK(c, 1e-8); } PERF_TEST_P(Size_MatType, multiplyScale, TYPICAL_MATS_CORE_ARITHM) { - Size sz = get<0>(GetParam()); - int type = get<1>(GetParam()); - cv::Mat a = Mat(sz, type); - cv::Mat b = Mat(sz, type); - cv::Mat c = Mat(sz, type); - double scale = 0.5; + Size sz = get<0>(GetParam()); + int type = get<1>(GetParam()); + cv::Mat a = Mat(sz, type); + cv::Mat b = Mat(sz, type); + cv::Mat c = Mat(sz, type); + double scale = 0.5; - declare.in(a, b, WARMUP_RNG).out(c); + declare.in(a, b, WARMUP_RNG).out(c); - if (CV_MAT_DEPTH(type) == CV_32S) - { - //According to docs, saturation is not applied when result is 32bit integer - a /= (2 << 16); - b /= (2 << 16); - } + if (CV_MAT_DEPTH(type) == CV_32S) + { + //According to docs, saturation is not applied when result is 32bit integer + a /= (2 << 16); + b /= (2 << 16); + } - TEST_CYCLE() multiply(a, b, c, scale); + TEST_CYCLE() multiply(a, b, c, scale); - SANITY_CHECK(c, 1e-8); + SANITY_CHECK(c, 1e-8); } From 699eda46b6278a6aeb6a9c58cbb605387b8a0075 Mon Sep 17 00:00:00 2001 From: Max Khardin Date: Sat, 4 Jan 2014 20:09:30 +0800 Subject: [PATCH 3/4] Remove three sneaky tabs --- modules/core/perf/perf_arithm.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/core/perf/perf_arithm.cpp b/modules/core/perf/perf_arithm.cpp index 977a70e0de..d3a75ca9cf 100644 --- a/modules/core/perf/perf_arithm.cpp +++ b/modules/core/perf/perf_arithm.cpp @@ -214,9 +214,9 @@ PERF_TEST_P(Size_MatType, multiply, TYPICAL_MATS_CORE_ARITHM) declare.in(a, b, WARMUP_RNG).out(c); if (CV_MAT_DEPTH(type) == CV_32S) { - //According to docs, saturation is not applied when result is 32bit integer - a /= (2 << 16); - b /= (2 << 16); + //According to docs, saturation is not applied when result is 32bit integer + a /= (2 << 16); + b /= (2 << 16); } TEST_CYCLE() multiply(a, b, c); From d8e5f1611b338290cc73b8c20a3076599d688fbd Mon Sep 17 00:00:00 2001 From: Max Khardin Date: Mon, 13 Jan 2014 15:55:49 +0400 Subject: [PATCH 4/4] Rewrite definition/declaration of variables to be more compact --- modules/core/perf/perf_arithm.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/core/perf/perf_arithm.cpp b/modules/core/perf/perf_arithm.cpp index d3a75ca9cf..3598c8639f 100644 --- a/modules/core/perf/perf_arithm.cpp +++ b/modules/core/perf/perf_arithm.cpp @@ -207,9 +207,7 @@ PERF_TEST_P(Size_MatType, multiply, TYPICAL_MATS_CORE_ARITHM) { Size sz = get<0>(GetParam()); int type = get<1>(GetParam()); - cv::Mat a = Mat(sz, type); - cv::Mat b = Mat(sz, type); - cv::Mat c = Mat(sz, type); + cv::Mat a(sz, type), b(sz, type), c(sz, type); declare.in(a, b, WARMUP_RNG).out(c); if (CV_MAT_DEPTH(type) == CV_32S) @@ -228,9 +226,7 @@ PERF_TEST_P(Size_MatType, multiplyScale, TYPICAL_MATS_CORE_ARITHM) { Size sz = get<0>(GetParam()); int type = get<1>(GetParam()); - cv::Mat a = Mat(sz, type); - cv::Mat b = Mat(sz, type); - cv::Mat c = Mat(sz, type); + cv::Mat a(sz, type), b(sz, type), c(sz, type); double scale = 0.5; declare.in(a, b, WARMUP_RNG).out(c);