/********************************************************************** ** BenchmarkInfo ** ** A benchmark for Qt/Embedded ** ** Copyright (C) 2004 Michael Lauer ** Inspired by ZBench (C) 2002 Satoshi ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ /* OPIE */ #include #include #include #include #include /* QT */ #include #include #include #include #include #include #include #include #include #include #include /* STD */ #include #include #include #include #include "benchmarkinfo.h" extern "C" { void BenchFFT( void ); double dhry_main( int ); } #define DHRYSTONE_RUNS 20000000 #define TEST_DURATION 3 //=========================================================================== class BenchmarkPaintWidget : public QWidget { public: BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever ) { resize( QApplication::desktop()->size() ); show(); p.begin( this ); }; ~BenchmarkPaintWidget() { p.end(); hide(); }; QPainter p; }; //=========================================================================== BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags ) : QWidget( parent, name, wFlags ) { setMinimumSize( 200, 150 ); QVBoxLayout* vb = new QVBoxLayout( this ); vb->setSpacing( 4 ); vb->setMargin( 4 ); tests = new QListView( this ); tests->setMargin( 1 ); tests->addColumn( "Tests" ); tests->addColumn( "Results" ); tests->setShowSortIndicator( true ); test_alu = new QCheckListItem( tests, "1: Integer Arithmetic ", QCheckListItem::CheckBox ); test_alu->setText( 1, "n/a" ); test_fpu = new QCheckListItem( tests, "2: Floating Point Unit ", QCheckListItem::CheckBox ); test_fpu->setText( 1, "n/a" ); test_txt = new QCheckListItem( tests, "3: Text Rendering ", QCheckListItem::CheckBox ); test_txt->setText( 1, "n/a" ); test_gfx = new QCheckListItem( tests, "4: Gfx Rendering ", QCheckListItem::CheckBox ); test_gfx->setText( 1, "n/a" ); test_ram = new QCheckListItem( tests, "5: RAM Performance ", QCheckListItem::CheckBox ); test_ram->setText( 1, "n/a" ); test_sd = new QCheckListItem( tests, "6: SD Card Performance ", QCheckListItem::CheckBox ); test_sd->setText( 1, "n/a" ); test_cf = new QCheckListItem( tests, "7: CF Card Performance ", QCheckListItem::CheckBox ); test_cf->setText( 1, "n/a" ); startButton = new QPushButton( tr( "&Start Tests!" ), this ); connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) ); vb->addWidget( tests, 2 ); vb->addWidget( startButton ); } BenchmarkInfo::~BenchmarkInfo() {} void BenchmarkInfo::run() { startButton->setText( "> Don't touch! Running Tests! Don't touch! <" ); qApp->processEvents(); QTime t; if ( test_alu->isOn() ) { int d = round( dhry_main( DHRYSTONE_RUNS ) ); test_alu->setText( 1, QString( "%1 dhrys" ).arg( QString::number( d ) ) ); test_alu->setOn( false ); } if ( test_fpu->isOn() ) { t.start(); BenchFFT(); test_fpu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) ); test_fpu->setOn( false ); } if ( test_txt->isOn() ) { int value = textRendering( TEST_DURATION ); test_txt->setText( 1, QString( "%1 chars/sec" ).arg( QString::number( value / TEST_DURATION ) ) ); test_txt->setOn( false ); } if ( test_gfx->isOn() ) { int value = gfxRendering( TEST_DURATION ); test_gfx->setText( 1, QString( "%1 gops/sec" ).arg( QString::number( value / 4 / TEST_DURATION ) ) ); // 4 tests test_gfx->setOn( false ); } if ( test_ram->isOn() ) { t.start(); writeFile( "/tmp/benchmarkFile.dat" ); // /tmp is supposed to be in RAM on a PDA readFile( "/tmp/benchmarkFile.dat" ); QFile::remove( "/tmp/benchmarkFile.dat" ); test_ram->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) ); test_ram->setOn( false ); } /* if ( test_cf->isOn() ) { t.start(); benchInteger(); test_alu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) ); test_alu->setOn( false ); } if ( test_sd->isOn() ) { t.start(); benchInteger(); test_alu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) ); test_alu->setOn( false ); } if ( ( which_clipb ) && ( buf.length() > 0 ) ) { clb = QApplication::clipboard(); clb->setText( dt_buf + buf ); } */ startButton->setText( tr( "&Start Tests!" ) ); } int BenchmarkInfo::textRendering( int seconds ) { QTime t; t.start(); int stop = t.elapsed() + seconds * 1000; int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; const QString text( "Opie Benchmark Test" ); int w = QApplication::desktop()->width(); int h = QApplication::desktop()->height(); srand( time( NULL ) ); BenchmarkPaintWidget bpw; int loops = 0; while ( t.elapsed() < stop ) { int k = rand() % 9; int s = rand() % 100; bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); bpw.p.setFont( QFont( "Vera", s ) ); bpw.p.drawText( rand() % w, rand() % h, text, text.length() ); ++loops; } return loops * text.length(); } int BenchmarkInfo::gfxRendering( int seconds ) { int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; int w = QApplication::desktop()->width(); int h = QApplication::desktop()->height(); srand( time( NULL ) ); BenchmarkPaintWidget bpw; QTime t; t.start(); int stop = t.elapsed() + seconds*1000; int loops = 0; while ( t.elapsed() < stop ) { int k = rand() % 9; bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h ); ++loops; } t.restart(); stop = t.elapsed() + seconds*1000; while ( t.elapsed() < stop ) { int k = rand() % 9; bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 ); ++loops; } QBrush br1; br1.setStyle( SolidPattern ); t.restart(); stop = t.elapsed() + seconds*1000; while ( t.elapsed() < stop ) { int k = rand() % 9; br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 ); ++loops; } QPixmap p = Resource::loadPixmap( "sysinfo/pattern" ); t.restart(); stop = t.elapsed() + seconds*1000; while ( t.elapsed() < stop ) { bpw.p.drawPixmap( rand()%w, rand()%h, p ); ++loops; } return loops; } // ********************************************************************** // Read & Write // v2.0.0 // ********************************************************************** #define BUFF_SIZE 8192 #define FILE_SIZE 1024 * 1024 // 1Mb char FileBuf[ BUFF_SIZE + 1 ]; bool BenchmarkInfo::writeFile( const QString& w_path ) { int i; int k; int n; int pos; int len; char *data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 62 // /*------------------------------------ int w_len; QFile writeFile( w_path ); srand( time( NULL ) ); for ( n = 0 ; n < 20 ; n++ ) { if ( ! writeFile.open( IO_WriteOnly ) ) { writeFile.close(); writeFile.remove(); return ( false ); } // ------------------------------------------ sequential write for ( k = 0 ; k < 256 ; k++ ) { n = rand() % 30; memcpy( &FileBuf[ k * 32 ], &data[ n ], 32 ); } for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) { w_len = writeFile.writeBlock( FileBuf, BUFF_SIZE ); if ( w_len != BUFF_SIZE ) { writeFile.close(); writeFile.remove(); return ( false ); } writeFile.flush(); } // ------------------------------------------ random write for ( i = 0 ; i < 400 ; i++ ) { len = rand() % 90 + 4000; for ( k = 0 ; k < 128 ; k++ ) { n = rand() % 30; memcpy( &FileBuf[ k * 8 ], &data[ n ], 32 ); } pos = rand() % ( FILE_SIZE - BUFF_SIZE ); writeFile.at( pos ); w_len = writeFile.writeBlock( FileBuf, len ); if ( w_len != len ) { writeFile.close(); writeFile.remove(); return ( false ); } writeFile.flush(); } writeFile.close(); } return ( true ); // ------------------------------------*/ /* ---------------------------------- srand( time( NULL ) ); FILE *fp; for( n= 0 ; n < 40 ; n++ ) { if (( fp = fopen( w_path, "wt" )) == NULL ) return( false ); memset( FileBuf, '\0', BUFF_SIZE+1 ); // ------------------------------------------ sequential write for( i= 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) { for( k= 0 ; k < 128 ; k++ ) { n = rand() % 30; memcpy( &FileBuf[k*8], &data[n], 32 ); } fputs( FileBuf, fp ); } // ------------------------------------------ random write for( i= 0 ; i < 300 ; i++ ) { memset( FileBuf, '\0', 130 ); len = rand() % 120 + 8; for( k= 0 ; k < 16 ; k++ ) { n = rand() % 54; memcpy( &FileBuf[k*8], &data[n], 8 ); } pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE ); fseek( fp, pos, SEEK_SET ); fputs( FileBuf, fp ); } fclose( fp ); } return( true ); -------------------------------------*/ } bool BenchmarkInfo::readFile( const QString& r_path ) { int i; int k; int len; int pos; int r_len; QFile readFile( r_path ); srand( time( NULL ) ); for ( k = 0 ; k < 200 ; k++ ) { if ( ! readFile.open( IO_ReadOnly ) ) { readFile.remove(); return ( false ); } // ------------------------------------------ sequential read readFile.at( 0 ); for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) { readFile.at( i * BUFF_SIZE ); r_len = readFile.readBlock( FileBuf, BUFF_SIZE ); if ( r_len != BUFF_SIZE ) { readFile.close(); readFile.remove(); return ( false ); } } // ------------------------------------------ random read for ( i = 0 ; i < 1000 ; i++ ) { len = rand() % 120 + 8; pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE ); readFile.at( pos ); r_len = readFile.readBlock( FileBuf, len ); if ( r_len != len ) { readFile.close(); readFile.remove(); return ( false ); } } readFile.close(); } return ( true ); }