perf_stat.cpp 2.16 KB
Newer Older
1 2 3 4 5
#include "perf_precomp.hpp"

using namespace std;
using namespace cv;
using namespace perf;
6 7
using std::tr1::make_tuple;
using std::tr1::get;
8

9
PERF_TEST_P(Size_MatType, sum, TYPICAL_MATS)
10
{
11 12
    Size sz = get<0>(GetParam());
    int type = get<1>(GetParam());
13 14 15 16

    Mat arr(sz, type);
    Scalar s;

17
    declare.in(arr, WARMUP_RNG).out(s);
18

19
    TEST_CYCLE() s = sum(arr);
20

21
    SANITY_CHECK(s, 1e-6, ERROR_RELATIVE);
22 23
}

24
PERF_TEST_P(Size_MatType, mean, TYPICAL_MATS)
25
{
26 27
    Size sz = get<0>(GetParam());
    int type = get<1>(GetParam());
28 29 30

    Mat src(sz, type);
    Scalar s;
31

32
    declare.in(src, WARMUP_RNG).out(s);
33

34
    TEST_CYCLE() s = mean(src);
35

36
    SANITY_CHECK(s, 1e-6);
37 38
}

39
PERF_TEST_P(Size_MatType, mean_mask, TYPICAL_MATS)
40
{
41 42
    Size sz = get<0>(GetParam());
    int type = get<1>(GetParam());
43 44 45 46

    Mat src(sz, type);
    Mat mask = Mat::ones(src.size(), CV_8U);
    Scalar s;
47

48
    declare.in(src, WARMUP_RNG).in(mask).out(s);
49

50
    TEST_CYCLE() s = mean(src, mask);
51

52
    SANITY_CHECK(s, 1e-6);
53 54
}

55
PERF_TEST_P(Size_MatType, meanStdDev, TYPICAL_MATS)
56
{
57 58
    Size sz = get<0>(GetParam());
    int matType = get<1>(GetParam());
59 60

    Mat src(sz, matType);
61 62
    Scalar mean;
    Scalar dev;
63

64
    declare.in(src, WARMUP_RNG).out(mean, dev);
65

66
    TEST_CYCLE() meanStdDev(src, mean, dev);
67

68 69
    SANITY_CHECK(mean, 1e-6);
    SANITY_CHECK(dev, 1e-6);
70 71
}

72
PERF_TEST_P(Size_MatType, meanStdDev_mask, TYPICAL_MATS)
73
{
74 75
    Size sz = get<0>(GetParam());
    int matType = get<1>(GetParam());
76 77 78

    Mat src(sz, matType);
    Mat mask = Mat::ones(sz, CV_8U);
79 80
    Scalar mean;
    Scalar dev;
81

82
    declare.in(src, WARMUP_RNG).in(mask).out(mean, dev);
83

84
    TEST_CYCLE() meanStdDev(src, mean, dev, mask);
85

86 87
    SANITY_CHECK(mean, 1e-6);
    SANITY_CHECK(dev, 1e-6);
88 89
}

90
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 ) ))
91
{
92 93
    Size sz = get<0>(GetParam());
    int matType = get<1>(GetParam());
94 95 96 97 98

    Mat src(sz, matType);
    int cnt = 0;

    declare.in(src, WARMUP_RNG);
99

100 101
    int runs = (sz.width <= 640) ? 8 : 1;
    TEST_CYCLE_MULTIRUN(runs) cnt = countNonZero(src);
102

103 104
    SANITY_CHECK(cnt);
}