Медленные функции для тестирования режима профилирования
This commit is contained in:
		@@ -7,6 +7,7 @@
 | 
			
		||||
#include <QCoreApplication>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QFile>
 | 
			
		||||
#include <QRandomGenerator>
 | 
			
		||||
#include <QTimer>
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -29,6 +30,40 @@ int unused( int a )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Медленная функция
 | 
			
		||||
 */
 | 
			
		||||
int slowFunction()
 | 
			
		||||
{
 | 
			
		||||
	constexpr int size = 16 * 1024;
 | 
			
		||||
	double a[size];
 | 
			
		||||
	for ( int i = 0; i < size; i++ )
 | 
			
		||||
	{
 | 
			
		||||
		a[i] = QRandomGenerator::global()->bounded( 4 );
 | 
			
		||||
		for ( int j = 0; j < i; j++ ) a[i] += sin( a[j] );
 | 
			
		||||
		a[0] += a[i];
 | 
			
		||||
	}
 | 
			
		||||
	return( qRound( a[0] ) );
 | 
			
		||||
} // slowFunction
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Быстрая функция
 | 
			
		||||
 */
 | 
			
		||||
int fastFunction()
 | 
			
		||||
{
 | 
			
		||||
	constexpr int size = 8 * 1024;
 | 
			
		||||
	double a[size];
 | 
			
		||||
	for ( int i = 0; i < size; i++ )
 | 
			
		||||
	{
 | 
			
		||||
		a[i] = QRandomGenerator::global()->bounded( 4 );
 | 
			
		||||
		for ( int j = 0; j < i; j++ ) a[i] += sin( a[j] );
 | 
			
		||||
		a[0] += a[i];
 | 
			
		||||
	}
 | 
			
		||||
	return( qRound( a[0] ) );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \brief Основная функция
 | 
			
		||||
 * \param argc Количество параметров командной строки
 | 
			
		||||
@@ -67,6 +102,11 @@ int main( int argc, char** argv )
 | 
			
		||||
	QObject::connect( &app, SIGNAL(aboutToQuit()), &p, SLOT(process()));
 | 
			
		||||
	QTimer::singleShot( 100, &app, SLOT(quit()));
 | 
			
		||||
 | 
			
		||||
	#ifdef PROFILE
 | 
			
		||||
	qCritical() << "Slow: " << slowFunction();
 | 
			
		||||
	qCritical() << "Fast: " << fastFunction();
 | 
			
		||||
	#endif
 | 
			
		||||
 | 
			
		||||
	int arr[3];
 | 
			
		||||
	qCritical() << arr[2];
 | 
			
		||||
	return( QCoreApplication::exec() );
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user