2011-01-24 18:33:01 +08:00
|
|
|
#include <iomanip>
|
|
|
|
#include "performance.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
|
|
|
|
|
|
|
void TestSystem::run()
|
|
|
|
{
|
2011-01-25 22:43:54 +08:00
|
|
|
// Run initializers
|
|
|
|
vector<Runnable*>::iterator it = inits_.begin();
|
|
|
|
for (; it != inits_.end(); ++it)
|
2011-01-26 15:49:56 +08:00
|
|
|
{
|
2011-01-25 22:43:54 +08:00
|
|
|
(*it)->run();
|
2011-01-26 15:49:56 +08:00
|
|
|
}
|
2011-01-25 22:43:54 +08:00
|
|
|
|
2011-01-24 18:33:01 +08:00
|
|
|
cout << setiosflags(ios_base::left);
|
2011-01-25 23:11:01 +08:00
|
|
|
cout << TAB << setw(10) << "CPU, ms" << setw(10) << "GPU, ms"
|
2011-01-26 15:49:56 +08:00
|
|
|
<< setw(10) << "SPEEDUP"
|
|
|
|
<< "DESCRIPTION\n";
|
2011-01-24 18:33:01 +08:00
|
|
|
cout << resetiosflags(ios_base::left);
|
|
|
|
|
2011-01-25 22:43:54 +08:00
|
|
|
// Run tests
|
|
|
|
it = tests_.begin();
|
2011-01-24 18:33:01 +08:00
|
|
|
for (; it != tests_.end(); ++it)
|
|
|
|
{
|
2011-01-25 22:43:54 +08:00
|
|
|
cout << endl << (*it)->name() << ":\n";
|
2011-01-25 23:11:01 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
(*it)->run();
|
2011-01-26 15:49:56 +08:00
|
|
|
flushSubtestData();
|
2011-01-25 23:11:01 +08:00
|
|
|
}
|
2011-01-26 15:49:56 +08:00
|
|
|
catch (const cv::Exception&)
|
2011-01-25 23:11:01 +08:00
|
|
|
{
|
2011-01-26 15:49:56 +08:00
|
|
|
resetSubtestData();
|
2011-01-25 23:11:01 +08:00
|
|
|
}
|
2011-01-24 18:33:01 +08:00
|
|
|
}
|
|
|
|
|
2011-01-26 15:49:56 +08:00
|
|
|
cout << setiosflags(ios_base::fixed);
|
|
|
|
cout << "\naverage GPU speedup: x"
|
|
|
|
<< setprecision(3) << speedup_total_ / num_subtests_called_
|
|
|
|
<< endl;
|
|
|
|
cout << resetiosflags(ios_base::fixed);
|
2011-01-24 18:33:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 15:49:56 +08:00
|
|
|
void TestSystem::flushSubtestData()
|
2011-01-24 18:33:01 +08:00
|
|
|
{
|
|
|
|
if (!can_flush_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int cpu_time = static_cast<int>(cpu_elapsed_ / getTickFrequency() * 1000.0);
|
|
|
|
int gpu_time = static_cast<int>(gpu_elapsed_ / getTickFrequency() * 1000.0);
|
|
|
|
|
2011-01-25 17:54:17 +08:00
|
|
|
double speedup = static_cast<double>(cpu_time) / std::max(1, gpu_time);
|
|
|
|
speedup_total_ += speedup;
|
|
|
|
|
2011-01-26 15:49:56 +08:00
|
|
|
cout << TAB << setiosflags(ios_base::left);
|
2011-01-24 18:33:01 +08:00
|
|
|
|
|
|
|
stringstream stream;
|
2011-01-26 15:49:56 +08:00
|
|
|
|
2011-01-24 18:33:01 +08:00
|
|
|
stream << cpu_time;
|
|
|
|
cout << setw(10) << stream.str();
|
|
|
|
|
|
|
|
stream.str("");
|
|
|
|
stream << gpu_time;
|
|
|
|
cout << setw(10) << stream.str();
|
|
|
|
|
|
|
|
stream.str("");
|
|
|
|
stream << "x" << setprecision(3) << speedup;
|
|
|
|
cout << setw(10) << stream.str();
|
|
|
|
|
|
|
|
cout << description_.str();
|
2011-01-26 15:49:56 +08:00
|
|
|
cout << resetiosflags(ios_base::left) << endl;
|
2011-01-24 18:56:11 +08:00
|
|
|
|
2011-01-25 16:32:45 +08:00
|
|
|
num_subtests_called_++;
|
2011-01-26 15:49:56 +08:00
|
|
|
resetSubtestData();
|
2011-01-24 18:33:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-25 22:43:54 +08:00
|
|
|
void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high)
|
|
|
|
{
|
|
|
|
mat.create(rows, cols, type);
|
|
|
|
RNG rng(0);
|
|
|
|
rng.fill(mat, RNG::UNIFORM, low, high);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-25 23:11:01 +08:00
|
|
|
int CV_CDECL cvErrorCallback(int /*status*/, const char* /*func_name*/,
|
|
|
|
const char* /*err_msg*/, const char* /*file_name*/,
|
|
|
|
int /*line*/, void* /*userdata*/)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-24 18:33:01 +08:00
|
|
|
int main()
|
|
|
|
{
|
2011-01-25 23:11:01 +08:00
|
|
|
redirectError(cvErrorCallback);
|
2011-01-24 18:33:01 +08:00
|
|
|
TestSystem::instance()->run();
|
|
|
|
return 0;
|
|
|
|
}
|