Skip to content

Commit

Permalink
[opencl] Add performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Aug 8, 2018
1 parent 66b02d6 commit e4228f4
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tests/src/core/testqgsopenclutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
#include <QString>
#include <QTemporaryFile>
#include <qgsapplication.h>
#include <chrono>

//header for class being tested
#include <qgsopenclutils.h>

#include <qgshillshaderenderer.h>
#include <qgsrasterlayer.h>

class TestQgsOpenClUtils: public QObject
{
Expand All @@ -46,7 +48,11 @@ class TestQgsOpenClUtils: public QObject

private:

// For performance testing
void testHillshade();

void _testMakeRunProgram();
void _testMakeHillshade( const QString title, const int loops );

cl::Program buildProgram( const cl::Context &context, const QString &source )
{
Expand All @@ -67,11 +73,15 @@ class TestQgsOpenClUtils: public QObject
return pgm;

}

QgsRasterLayer *mFloat32RasterLayer = nullptr;
};


void TestQgsOpenClUtils::init()
{
// Reset to default in case some tests mess it up
QgsOpenClUtils::setSourcePath( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/opencl_programs" ) ) );
}

void TestQgsOpenClUtils::cleanup()
Expand All @@ -89,6 +99,11 @@ void TestQgsOpenClUtils::initTestCase()

QgsApplication::init();
QgsApplication::initQgis();

QString float32FileName = QStringLiteral( TEST_DATA_DIR ) + '/' + "/raster/band1_float32_noct_epsg4326.tif";
QFileInfo float32RasterFileInfo( float32FileName );
mFloat32RasterLayer = new QgsRasterLayer( float32RasterFileInfo.filePath(),
float32RasterFileInfo.completeBaseName() );
}


Expand Down Expand Up @@ -183,6 +198,27 @@ void TestQgsOpenClUtils::testContext()
QVERIFY( QgsOpenClUtils::context()() != nullptr );
}

void TestQgsOpenClUtils::_testMakeHillshade( const QString title, const int loops )
{
std::chrono::time_point<std::chrono::system_clock> startTime( std::chrono::system_clock::now() );
for ( int i = 0 ; i < loops; i++ )
{
QgsHillshadeRenderer renderer( mFloat32RasterLayer->dataProvider(), 1, 35.0, 5000.0 );
QgsRasterBlock *block = renderer.block( 0, mFloat32RasterLayer->extent(), 401, 401 );
}
qDebug() << QStringLiteral( "%1 average for %2 loops: %3 ms" )
.arg( title )
.arg( loops )
.arg( std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now() - startTime ).count() / loops ) ;
}

void TestQgsOpenClUtils::testHillshade()
{
QgsOpenClUtils::setEnabled( true );
_testMakeHillshade( QStringLiteral( "OpenCL" ), 5 );
QgsOpenClUtils::setEnabled( false );
_testMakeHillshade( QStringLiteral( "CPU" ), 5 );
}

QGSTEST_MAIN( TestQgsOpenClUtils )
#include "testqgsopenclutils.moc"

0 comments on commit e4228f4

Please sign in to comment.