perf_stat.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "perf_precomp.hpp"
  2. namespace opencv_test
  3. {
  4. using namespace perf;
  5. PERF_TEST_P(Size_MatType, sum, TYPICAL_MATS)
  6. {
  7. Size sz = get<0>(GetParam());
  8. int type = get<1>(GetParam());
  9. Mat arr(sz, type);
  10. Scalar s;
  11. declare.in(arr, WARMUP_RNG).out(s);
  12. TEST_CYCLE() s = sum(arr);
  13. SANITY_CHECK(s, 1e-6, ERROR_RELATIVE);
  14. }
  15. PERF_TEST_P(Size_MatType, mean, TYPICAL_MATS)
  16. {
  17. Size sz = get<0>(GetParam());
  18. int type = get<1>(GetParam());
  19. Mat src(sz, type);
  20. Scalar s;
  21. declare.in(src, WARMUP_RNG).out(s);
  22. TEST_CYCLE() s = mean(src);
  23. SANITY_CHECK(s, 1e-5);
  24. }
  25. PERF_TEST_P(Size_MatType, mean_mask, TYPICAL_MATS)
  26. {
  27. Size sz = get<0>(GetParam());
  28. int type = get<1>(GetParam());
  29. Mat src(sz, type);
  30. Mat mask = Mat::ones(src.size(), CV_8U);
  31. Scalar s;
  32. declare.in(src, WARMUP_RNG).in(mask).out(s);
  33. TEST_CYCLE() s = mean(src, mask);
  34. SANITY_CHECK(s, 5e-5);
  35. }
  36. PERF_TEST_P(Size_MatType, meanStdDev, TYPICAL_MATS)
  37. {
  38. Size sz = get<0>(GetParam());
  39. int matType = get<1>(GetParam());
  40. Mat src(sz, matType);
  41. Scalar mean;
  42. Scalar dev;
  43. declare.in(src, WARMUP_RNG).out(mean, dev);
  44. TEST_CYCLE() meanStdDev(src, mean, dev);
  45. SANITY_CHECK(mean, 1e-5, ERROR_RELATIVE);
  46. SANITY_CHECK(dev, 1e-5, ERROR_RELATIVE);
  47. }
  48. PERF_TEST_P(Size_MatType, meanStdDev_mask, TYPICAL_MATS)
  49. {
  50. Size sz = get<0>(GetParam());
  51. int matType = get<1>(GetParam());
  52. Mat src(sz, matType);
  53. Mat mask = Mat::ones(sz, CV_8U);
  54. Scalar mean;
  55. Scalar dev;
  56. declare.in(src, WARMUP_RNG).in(mask).out(mean, dev);
  57. TEST_CYCLE() meanStdDev(src, mean, dev, mask);
  58. SANITY_CHECK(mean, 1e-5);
  59. SANITY_CHECK(dev, 1e-5);
  60. }
  61. PERF_TEST_P(Size_MatType, countNonZero, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ), testing::Values( CV_8UC1, CV_8SC1, CV_16UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_64FC1 ) ))
  62. {
  63. Size sz = get<0>(GetParam());
  64. int matType = get<1>(GetParam());
  65. Mat src(sz, matType);
  66. int cnt = 0;
  67. declare.in(src, WARMUP_RNG);
  68. int runs = (sz.width <= 640) ? 8 : 1;
  69. TEST_CYCLE_MULTIRUN(runs) cnt = countNonZero(src);
  70. SANITY_CHECK(cnt);
  71. }
  72. } // namespace