summaryrefslogtreecommitdiff
path: root/noncore/settings/sysinfo/benchmarkinfo.cpp
Unidiff
Diffstat (limited to 'noncore/settings/sysinfo/benchmarkinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/benchmarkinfo.cpp453
1 files changed, 453 insertions, 0 deletions
diff --git a/noncore/settings/sysinfo/benchmarkinfo.cpp b/noncore/settings/sysinfo/benchmarkinfo.cpp
new file mode 100644
index 0000000..62146f7
--- a/dev/null
+++ b/noncore/settings/sysinfo/benchmarkinfo.cpp
@@ -0,0 +1,453 @@
1/**********************************************************************
2** BenchmarkInfo
3**
4** A benchmark for Qt/Embedded
5**
6** Copyright (C) 2004 Michael Lauer <mickey@vanille.de>
7** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp>
8**
9** This file may be distributed and/or modified under the terms of the
10** GNU General Public License version 2 as published by the Free Software
11** Foundation and appearing in the file LICENSE.GPL included in the
12** packaging of this file.
13**
14** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
15** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16**
17**********************************************************************/
18
19/* OPIE */
20#include <qpe/qpeapplication.h>
21#include <qpe/qcopenvelope_qws.h>
22#include <qpe/qpedecoration_qws.h>
23#include <qpe/resource.h>
24#include <qpe/config.h>
25
26/* QT */
27#include <qlayout.h>
28#include <qfiledialog.h>
29#include <qlabel.h>
30#include <qpainter.h>
31#include <qdirectpainter_qws.h>
32#include <qapplication.h>
33#include <qpushbutton.h>
34#include <qclipboard.h>
35#include <qtimer.h>
36#include <qcolor.h>
37#include <qpushbutton.h>
38
39/* STD */
40#include <stdio.h>
41#include <time.h>
42#include <stdlib.h>
43
44#include "benchmarkinfo.h"
45
46extern "C"
47{
48 void BenchFFT( void );
49}
50
51//===========================================================================
52
53class BenchmarkPaintWidget : public QWidget
54{
55 public:
56 BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever )
57 {
58 resize( QApplication::desktop()->size() );
59 show();
60 p.begin( this );
61 };
62
63 ~BenchmarkPaintWidget()
64 {
65 p.end();
66 hide();
67 };
68
69 QPainter p;
70};
71
72//===========================================================================
73
74BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags )
75 : QWidget( parent, name, wFlags )
76{
77
78 setMinimumSize( 200, 150 );
79
80 QVBoxLayout* vb = new QVBoxLayout( this );
81 vb->setSpacing( 4 );
82 vb->setMargin( 4 );
83
84 tests = new QListView( this );
85 tests->setMargin( 1 );
86 tests->addColumn( "Tests" );
87 tests->addColumn( "Results" );
88 tests->setShowSortIndicator( true );
89
90 test_alu = new QCheckListItem( tests, "1: Integer Arithmetic ", QCheckListItem::CheckBox );
91 test_alu->setText( 1, "n/a" );
92 test_fpu = new QCheckListItem( tests, "2: Floating Point Unit ", QCheckListItem::CheckBox );
93 test_fpu->setText( 1, "n/a" );
94 test_txt = new QCheckListItem( tests, "3: Text Rendering ", QCheckListItem::CheckBox );
95 test_txt->setText( 1, "n/a" );
96 test_gfx = new QCheckListItem( tests, "4: Gfx Rendering ", QCheckListItem::CheckBox );
97 test_gfx->setText( 1, "n/a" );
98 test_ram = new QCheckListItem( tests, "5: RAM Performance ", QCheckListItem::CheckBox );
99 test_ram->setText( 1, "n/a" );
100 test_sd = new QCheckListItem( tests, "6: SD Card Performance ", QCheckListItem::CheckBox );
101 test_sd->setText( 1, "n/a" );
102 test_cf = new QCheckListItem( tests, "7: CF Card Performance ", QCheckListItem::CheckBox );
103 test_cf->setText( 1, "n/a" );
104
105 startButton = new QPushButton( tr( "&Start Tests!" ), this );
106 connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) );
107
108 vb->addWidget( tests, 2 );
109 vb->addWidget( startButton );
110}
111
112
113BenchmarkInfo::~BenchmarkInfo()
114{}
115
116
117void BenchmarkInfo::run()
118{
119 startButton->setText( "> Don't touch! Running Tests! Don't touch! <" );
120 qApp->processEvents();
121 QTime t;
122
123 if ( test_alu->isOn() )
124 {
125 t.start();
126 benchInteger();
127 test_alu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) );
128 test_alu->setOn( false );
129 }
130
131 if ( test_fpu->isOn() )
132 {
133 t.start();
134 BenchFFT();
135 test_fpu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) );
136 test_fpu->setOn( false );
137 }
138
139 if ( test_txt->isOn() )
140 {
141 t.start();
142 paintChar();
143 test_txt->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) );
144 test_txt->setOn( false );
145 }
146
147 if ( test_gfx->isOn() )
148 {
149 t.start();
150 paintLineRect();
151 test_gfx->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) );
152 test_gfx->setOn( false );
153 }
154
155 if ( test_ram->isOn() )
156 {
157 t.start();
158 writeFile( "/tmp/benchmarkFile.dat" ); // /tmp is supposed to be in RAM on a PDA
159 readFile( "/tmp/benchmarkFile.dat" );
160 QFile::remove( "/tmp/benchmarkFile.dat" );
161 test_ram->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) );
162 test_ram->setOn( false );
163 }
164/*
165 if ( test_cf->isOn() )
166 {
167 t.start();
168 benchInteger();
169 test_alu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) );
170 test_alu->setOn( false );
171 }
172
173 if ( test_sd->isOn() )
174 {
175 t.start();
176 benchInteger();
177 test_alu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) );
178 test_alu->setOn( false );
179 }
180
181 if ( ( which_clipb ) && ( buf.length() > 0 ) )
182 {
183 clb = QApplication::clipboard();
184 clb->setText( dt_buf + buf );
185 }
186 */
187
188 startButton->setText( tr( "&Start Tests!" ) );
189}
190
191
192void BenchmarkInfo::benchInteger() const
193{
194 long dummy = 1;
195
196 for ( long i= 0 ; i < INT_TEST_ITERATIONS ; i++ )
197 {
198 for ( long j= 0 ; j < INT_TEST_ITERATIONS ; j++ )
199 {
200 for( long k= 0 ; k < INT_TEST_ITERATIONS ; k++ )
201 {
202 long xx = ( rand() % 1000 + 111 ) * 7 / 3 + 31;
203 long yy = ( rand() % 100 + 23 ) * 11 / 7 + 17;
204 long zz = ( rand() % 100 + 47 ) * 13 / 11 - 211;
205 dummy = xx * yy / zz;
206 dummy *= 23;
207 dummy += ( xx - yy + zz );
208 dummy -= ( xx + yy - zz );
209 dummy *= ( xx * zz * yy );
210 dummy /= 1 + ( xx * yy * zz );
211 }
212 }
213 }
214}
215
216
217void BenchmarkInfo::paintChar()
218{
219 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 };
220 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 };
221 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 };
222 const QString text( "Opie Benchmark Test" );
223
224 int w = QApplication::desktop()->width();
225 int h = QApplication::desktop()->height();
226
227 srand( time( NULL ) );
228
229 BenchmarkPaintWidget bpw;
230
231 for ( int i = 0; i < CHAR_TEST_ITERATIONS; ++i )
232 {
233 int k = rand() % 9;
234 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
235 bpw.p.setFont( QFont( "Vera", k*10 ) );
236 bpw.p.drawText( rand() % w, rand() % h, text, text.length() );
237 }
238}
239
240void BenchmarkInfo::paintLineRect()
241{
242 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 };
243 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 };
244 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 };
245
246 int w = QApplication::desktop()->width();
247 int h = QApplication::desktop()->height();
248
249 srand( time( NULL ) );
250
251 BenchmarkPaintWidget bpw;
252
253 for ( int i = 0; i < DRAW_TEST_ITERATIONS*3; ++i )
254 {
255 int k = rand() % 9;
256 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
257 bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h );
258 }
259
260 for ( int i = 0; i < DRAW_TEST_ITERATIONS; ++i )
261 {
262 int k = rand() % 9;
263 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
264 bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 );
265 }
266
267 QBrush br1;
268 br1.setStyle( SolidPattern );
269
270 for ( int i = 0; i < DRAW_TEST_ITERATIONS*2; ++i )
271 {
272 int k = rand() % 9;
273 br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
274 bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 );
275 }
276
277 QPixmap p = Resource::loadPixmap( "pattern" );
278 for ( int i = 0; i < DRAW_TEST_ITERATIONS; ++i )
279 {
280 bpw.p.drawPixmap( rand()%w, rand()%h, p );
281 }
282
283
284}
285
286// **********************************************************************
287// Read & Write
288// v2.0.0
289// **********************************************************************
290#define BUFF_SIZE 8192
291#define FILE_SIZE 1024 * 1024 // 1Mb
292
293char FileBuf[ BUFF_SIZE + 1 ];
294
295bool BenchmarkInfo::writeFile( const QString& w_path )
296{
297 int i;
298 int k;
299 int n;
300 int pos;
301 int len;
302 char *data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 62
303
304
305 // /*------------------------------------
306 int w_len;
307
308 QFile writeFile( w_path );
309 srand( time( NULL ) );
310
311 for ( n = 0 ; n < 20 ; n++ )
312 {
313 if ( ! writeFile.open( IO_WriteOnly ) )
314 {
315 writeFile.close();
316 writeFile.remove();
317 return ( false );
318 }
319 // ------------------------------------------ sequential write
320 for ( k = 0 ; k < 256 ; k++ )
321 {
322 n = rand() % 30;
323 memcpy( &FileBuf[ k * 32 ], &data[ n ], 32 );
324 }
325
326 for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ )
327 {
328 w_len = writeFile.writeBlock( FileBuf, BUFF_SIZE );
329 if ( w_len != BUFF_SIZE )
330 {
331 writeFile.close();
332 writeFile.remove();
333 return ( false );
334 }
335 writeFile.flush();
336 }
337 // ------------------------------------------ random write
338 for ( i = 0 ; i < 400 ; i++ )
339 {
340 len = rand() % 90 + 4000;
341 for ( k = 0 ; k < 128 ; k++ )
342 {
343 n = rand() % 30;
344 memcpy( &FileBuf[ k * 8 ], &data[ n ], 32 );
345 }
346 pos = rand() % ( FILE_SIZE - BUFF_SIZE );
347
348 writeFile.at( pos );
349 w_len = writeFile.writeBlock( FileBuf, len );
350 if ( w_len != len )
351 {
352 writeFile.close();
353 writeFile.remove();
354 return ( false );
355 }
356 writeFile.flush();
357 }
358 writeFile.close();
359 }
360 return ( true );
361 // ------------------------------------*/
362
363 /* ----------------------------------
364 srand( time( NULL ) );
365
366 FILE *fp;
367
368 for( n= 0 ; n < 40 ; n++ )
369 {
370 if (( fp = fopen( w_path, "wt" )) == NULL )
371 return( false );
372 memset( FileBuf, '\0', BUFF_SIZE+1 );
373 // ------------------------------------------ sequential write
374 for( i= 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ )
375 {
376 for( k= 0 ; k < 128 ; k++ )
377 {
378 n = rand() % 30;
379 memcpy( &FileBuf[k*8], &data[n], 32 );
380 }
381 fputs( FileBuf, fp );
382 }
383 // ------------------------------------------ random write
384 for( i= 0 ; i < 300 ; i++ )
385 {
386 memset( FileBuf, '\0', 130 );
387 len = rand() % 120 + 8;
388 for( k= 0 ; k < 16 ; k++ )
389 {
390 n = rand() % 54;
391 memcpy( &FileBuf[k*8], &data[n], 8 );
392 }
393 pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE );
394
395 fseek( fp, pos, SEEK_SET );
396 fputs( FileBuf, fp );
397 }
398 fclose( fp );
399 }
400 return( true );
401 -------------------------------------*/
402}
403
404
405bool BenchmarkInfo::readFile( const QString& r_path )
406{
407 int i;
408 int k;
409 int len;
410 int pos;
411 int r_len;
412
413 QFile readFile( r_path );
414 srand( time( NULL ) );
415
416 for ( k = 0 ; k < 200 ; k++ )
417 {
418 if ( ! readFile.open( IO_ReadOnly ) )
419 {
420 readFile.remove();
421 return ( false );
422 }
423 // ------------------------------------------ sequential read
424 readFile.at( 0 );
425 for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ )
426 {
427 readFile.at( i * BUFF_SIZE );
428 r_len = readFile.readBlock( FileBuf, BUFF_SIZE );
429 if ( r_len != BUFF_SIZE )
430 {
431 readFile.close();
432 readFile.remove();
433 return ( false );
434 }
435 }
436 // ------------------------------------------ random read
437 for ( i = 0 ; i < 1000 ; i++ )
438 {
439 len = rand() % 120 + 8;
440 pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE );
441 readFile.at( pos );
442 r_len = readFile.readBlock( FileBuf, len );
443 if ( r_len != len )
444 {
445 readFile.close();
446 readFile.remove();
447 return ( false );
448 }
449 }
450 readFile.close();
451 }
452 return ( true );
453}