⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zbench.cpp

📁 OPIE/Qtopia的测试工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// zbench.cpp// ******************************************************************// Benchmark v1.0// 1. Integer// 2. Floatingpoint// 3. Draw character// 4. Draw graphic( line & rect )// ******************************************************************// ******************************************************************// Copyright (c) 2002- Satoshi, All Rights Reserved.// // This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.////// Author : Satoshi ( af230533@im07.alpha-net.ne.jp )// ******************************************************************// #include "qpe/resource.h"		// qpe/// #include <qmenubar.h>#include <qwidgetstack.h>// #include <qpe/qpetoolbar.h>		// qpe/#include <qaction.h>#include <qfiledialog.h>#include <qmessagebox.h>#include <qpe/qpemenubar.h>#include <qpopupmenu.h>#include <qlabel.h>#include <qpainter.h>#include <qkeycode.h>#include <qapplication.h>#include <qpushbutton.h>#include <qclipboard.h>#include <qtimer.h>#include <qsizepolicy.h>#include <qpe/qpeapplication.h>		// qpe/#include <qpe/qcopenvelope_qws.h>	// qpe/#include <qpe/qpedecoration_qws.h>	// qpe/#include <qpe/config.h>#include <qcolor.h>#include <qclipboard.h>#include <qdialog.h>#include <qcheckbox.h>#include <stdio.h>#include <time.h>#include <stdlib.h>#include "zbench.h"extern "C" { void   BenchFFT( void ); }extern "C" { void   BenchInteger( void ); }//===========================================================================AppZBench::AppZBench( QWidget *parent, const char *name, int wFlags )    : QMainWindow( parent, name, wFlags ){    popStart = new QPopupMenu( this );	QAction *a = new QAction( tr( "&Setting" ), QString::null, Key_S + CTRL, this, 0 );	connect( a, SIGNAL( activated() ), this, SLOT( start_dialog() ) );	a->addTo( popStart );    menuBar  = new QPEMenuBar( this );	menuBar->insertItem( tr( "Start" ), popStart );	PushB = new QPushButton( " ZBench START ! ", this );	connect( PushB, SIGNAL( clicked() ), this, SLOT( start_bench() ) );	PushB->hide();    setCaption( tr("[ ZBench ] benchmark test program v2.0") );	which_int     = true;	which_float   = true;	which_text    = true;	which_graphic = true;	which_main    = false;	which_sd      = false;	which_cf      = false;	which_clipb   = true;}AppZBench::~AppZBench(){}// **********************************************************************// Start ZBench// **********************************************************************void AppZBench::start_dialog( void ){	StartDialog stDialog( this, "startdialog", true, 0 );	if ( stDialog.exec() == QDialog::Accepted )	{		x_size = stDialog.x_size;		y_size = stDialog.y_size;		which_int     = stDialog.which_int;		which_float   = stDialog.which_float;		which_text    = stDialog.which_text;		which_graphic = stDialog.which_graphic; 		which_main    = stDialog.which_main;		which_sd      = stDialog.which_sd;		which_cf      = stDialog.which_cf;		which_clipb   = stDialog.which_clipb;	}	PushB->setGeometry( ( x_size - 200 )/ 2, y_size / 2 - 70, 200, 50 );	PushB->show();}void AppZBench::start_bench( void ){	QTime		t;	char		*msg1 = "Don't touch the window!";	char		*msg2 = "Please wait a minute.";	QString		main_file = "/home/zaurus/ZBench.dat";	QString		sd_file = "/var/mnt/card/ZBench.dat";	QString		cf_file = "/var/mnt/cf/ZBench.dat";	QPainter    pt;	PushB->hide();		// **********************************		// start !!!		// **********************************		//----------------------------------- message		pt.begin( this );		pt.setPen( QColor( 255, 0, 0 ));		pt.drawText( ( x_size - strlen( msg1 )*10 )/ 2, y_size / 2 + 30, msg1, strlen( msg1 ) );		pt.drawText( ( x_size - strlen( msg2 )*10 )/ 2, y_size / 2 + 70, msg2, strlen( msg2 ) );		pt.end();		// ---------------------------------- Integer		if ( which_int )		{			t.start();			BenchInteger();			t1 = t.elapsed();		}		// ---------------------------------- FFT		if ( which_float )		{			t.start();			BenchFFT();			t2 = t.elapsed();		}		// ---------------------------------- main read & write File	v2.0.0		if ( which_main )		{			t.start();			main_wt = writeFile( main_file );			t6 = t.elapsed();			t.start();			main_rd = readFile( main_file );			t5 = t.elapsed();			QFile	mainFile( main_file );			mainFile.remove();		}		// ---------------------------------- sd read & write File	v2.0.0		if ( which_sd )		{			t.start();			sd_wt = writeFile( sd_file );			t8 = t.elapsed();			t.start();			sd_rd = readFile( sd_file );			t7 = t.elapsed();			QFile	sdFile( sd_file );			sdFile.remove();		}		// ---------------------------------- cf read & write File	v2.0.0		if ( which_cf )		{			t.start();			cf_wt = writeFile( cf_file );			t10 = t.elapsed();			t.start();			cf_rd = readFile( cf_file );			t9 = t.elapsed();			QFile	cfFile( cf_file );			cfFile.remove();		}		// ---------------------------------- draw Char		if ( which_text )		{			t.start();			paintChar();			t3 = t.elapsed();		}		// ---------------------------------- draw Graphic		if ( which_graphic )		{			t.start();			paintLineRect();			t4 = t.elapsed();		}		// ---------------------------------- end		QTime	tt;		QDate	dd;		QString buf1;		QString buf2;		QString buf3;		QString buf4;		QString buf5;		QString buf6;		QString buf7;		QString buf8;		QString buf9;		QString buf10;		tt = QTime::currentTime();		dd = QDate::currentDate();		dt_buf.sprintf( "- %04d.%02d.%02d %02d:%02d:%02d -\n", dd.year(), dd.month(), dd.day(), tt.hour(), tt.minute(), tt.second() );		if ( which_int )			buf1.sprintf( "[    Integer     ] time is %2d.%03d sec\n", t1/1000, t1%1000 );		if ( which_float )			buf2.sprintf( "[ Floating point ] time is %2d.%03d sec\n", t2/1000, t2%1000 );		if ( which_text )			buf3.sprintf( "[   Draw Text    ] time is %2d.%03d sec\n", t3/1000, t3%1000 );		if ( which_graphic )			buf4.sprintf( "[  Draw Graphic  ] time is %2d.%03d sec\n", t4/1000, t4%1000 );		if ( which_main )		{			if ( main_rd )				buf5.sprintf( "[ main unit ] read time is %2d.%03d sec\n", t5/1000, t5%1000 );			else				buf5.sprintf( "[ main unit ] read error!\n" );			if ( main_wt )				buf6.sprintf( "             write time is %2d.%03d sec\n", t6/1000, t6%1000 );			else				buf6.sprintf( "             write error!\n" );		}		if ( which_sd )		{			if ( sd_rd )				buf7.sprintf( "[ SD card ]   read time is %2d.%03d sec\n", t7/1000, t7%1000 );			else				buf7.sprintf( "[ SD card ]   read error!\n" );			if ( sd_wt )				buf8.sprintf( "             write time is %2d.%03d sec\n", t8/1000, t8%1000 );			else				buf8.sprintf( "             write error!\n" );		}		if ( which_cf )		{			if ( cf_rd )				buf9.sprintf( "[ CF card ]   read time is %2d.%03d sec\n", t9/1000, t9%1000 );			else				buf9.sprintf( "[ CF card ]   read error!\n" );			if ( cf_wt )				buf10.sprintf( "             write time is %2d.%03d sec\n", t10/1000, t10%1000 );			else				buf10.sprintf( "             write error!\n" );		}		buf = buf1 + buf2 + buf3 + buf4 + buf5 + buf6 + buf7 + buf8 + buf9 + buf10;/*------		sprintf( buf, "Integer time is %d.%03d sec\nFloating point time is %d.%03d sec\nDraw Text time is %d.%03d sec\nDraw Graphic time is %d.%03d sec", 	 					t1/1000, t1%1000, 	 					t2/1000, t2%1000, 	 					t3/1000, t3%1000, 	 					t4/1000, t4%1000 );------*/		if ( buf.length() > 0 )		{			outputResult();			QMessageBox::information( this, tr("- ZBench - result time"), tr( buf ));		}		else		{			QMessageBox::information( this, tr("- ZBench - result time"), tr( "nothing !!!" ));		}		if (( which_clipb ) && ( buf.length() > 0 ))		{			clb = QApplication::clipboard();			clb->setText( dt_buf + buf );		}//	PushB->show();	close();}// **********************************************************************// Darw Text// **********************************************************************void AppZBench::outputResult(){	QString		out_file = "/home/zaurus/Documents/Text_Files/ZBench_result.txt";	QFile	writeFile( out_file );	if ( buf.length() > 0 )	{//		if ( writeFile.open( IO_Append ))	// IO_Append can't use ???/*----		if ( writeFile.open( IO_WriteOnly ))		{//			QTextStream		stream( &writeFile );//			stream << dt_buf + buf + "\n";			writeFile.writeBlock( r_buf, r_buf.length() );			writeFile.writeBlock( dt_buf, dt_buf.length() );			writeFile.writeBlock( buf + "\n", buf.length() + 1 );			writeFile.close();		}------*/			FILE	*fp;			if (( fp = fopen( out_file, "at" )) != NULL )			{				fputs( dt_buf, fp );				fputs( buf, fp );				fputs( "\n", fp );				fclose( fp );			}	}}// **********************************************************************// Darw Text// **********************************************************************void AppZBench::paintChar(){	int         i;	int         k;	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         xx;	int         yy;	char       *wk = "ZaurusBenchTest";	QPainter    pt;	srand( time( NULL ) );	pt.begin( this );	for ( i= 0 ; i < CHAR_TEST_COUNT ; i++ )	{		k = rand() % 9;		pt.setPen( QColor( rr[k], gg[k], bb[k] ));		xx = rand() % ( x_size - 100 );		yy = rand() % ( y_size - CAPTION_Y_SIZE - 1 ) + CAPTION_Y_SIZE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -