float r = 0.0f;
RNG rng(1);
double t1 = (double)getTickCount();
for (size_t i = 0; i < 10000; i++)
{
Mat a, b, c;
a = Mat::ones(512, 512, CV_32FC1);
a = a * rng.uniform(0.0f, 100.0f);
b = Mat::ones(512, 512, CV_32FC1);
b = b * rng.uniform(0.0f, 100.0f);
c = Mat::ones(512, 512, CV_32FC1);
c = c * rng.uniform(0.0f, 100.0f);
Mat d = (a.mul(b) + c)*1000.f;
int x = 511 * rng.uniform(0.0f, 1.0f);
int y = 511 * rng.uniform(0.0f, 1.0f);
r = r + d.at<float>(x, y);
}
t1 = (double)getTickCount() - t1;
std::cout << "compute time :" << t1*1000.0 / cv::getTickFrequency() << " ms \n";
cout << r << endl;
r = 0.0f;
double t2 = (double)getTickCount();
for (size_t i = 0; i < 10000; i++)
{
cv::Mat a, b, c;
a = Mat::ones(512, 512, CV_32FC1);
a = a * rng.uniform(0.0f, 100.0f);
b = Mat::ones(512, 512, CV_32FC1);
b = b * rng.uniform(0.0f, 100.0f);
c = Mat::ones(512, 512, CV_32FC1);
c = c * rng.uniform(0.0f, 100.0f);
Mat d = a.mul(b);
d = d + c;
d = d*1000.f;
int x = 511 * rng.uniform(0.0f, 1.0f);
int y = 511 * rng.uniform(0.0f, 1.0f);
r = r + d.at<float>(x, y);
}
t2 = (double)getTickCount() - t2;
std::cout << "compute time :" << t2*1000.0 / cv::getTickFrequency() << " ms \n";
cout << r << endl;
r = 0.0f;
double t3 = (double)getTickCount();
for (size_t i = 0; i < 10000; i++)
{
cv::Mat a, b, c;
a = Mat::ones(512, 512, CV_32FC1);
a = a * rng.uniform(0.0f, 100.0f);
b = Mat::ones(512, 512, CV_32FC1);
b = b * rng.uniform(0.0f, 100.0f);
c = Mat::ones(512, 512, CV_32FC1);
c = c * rng.uniform(0.0f, 100.0f);
Mat d = a.mul(b);
d += c;
d *= 1000.f;
int x = 511 * rng.uniform(0.0f, 1.0f);
int y = 511 * rng.uniform(0.0f, 1.0f);
r = r + d.at<float>(x, y);
}
t3 = (double)getTickCount() - t3;
std::cout << "compute time :" << t3*1000.0 / cv::getTickFrequency() << " ms \n";
cout << r << endl;