-rw-r--r-- | noncore/settings/sysinfo/benchmarkinfo.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/sysinfo/benchmarkinfo.cpp b/noncore/settings/sysinfo/benchmarkinfo.cpp index 2a52b00..96bcdfc 100644 --- a/noncore/settings/sysinfo/benchmarkinfo.cpp +++ b/noncore/settings/sysinfo/benchmarkinfo.cpp | |||
@@ -1,480 +1,480 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** BenchmarkInfo | 2 | ** BenchmarkInfo |
3 | ** | 3 | ** |
4 | ** A benchmark for Qt/Embedded | 4 | ** A benchmark for Qt/Embedded |
5 | ** | 5 | ** |
6 | ** Copyright (C) 2004 Michael Lauer <mickey@vanille.de> | 6 | ** Copyright (C) 2004 Michael Lauer <mickey@vanille.de> |
7 | ** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp> | 7 | ** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp> |
8 | ** | 8 | ** |
9 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 11 | ** Foundation and appearing in the file LICENSE.GPL included in the |
12 | ** packaging of this file. | 12 | ** packaging of this file. |
13 | ** | 13 | ** |
14 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 15 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
16 | ** | 16 | ** |
17 | **********************************************************************/ | 17 | **********************************************************************/ |
18 | 18 | ||
19 | #include "benchmarkinfo.h" | 19 | #include "benchmarkinfo.h" |
20 | 20 | ||
21 | /* OPIE */ | 21 | /* OPIE */ |
22 | #include <opie2/ostorageinfo.h> | 22 | #include <opie2/ostorageinfo.h> |
23 | #include <opie2/olistview.h> | 23 | #include <opie2/olistview.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | #include <qpe/qpedecoration_qws.h> | 26 | #include <qpe/qpedecoration_qws.h> |
27 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
28 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
29 | 29 | ||
30 | /* QT */ | 30 | /* QT */ |
31 | #include <qclipboard.h> | 31 | #include <qclipboard.h> |
32 | #include <qcolor.h> | 32 | #include <qcolor.h> |
33 | #include <qcombobox.h> | 33 | #include <qcombobox.h> |
34 | #include <qdirectpainter_qws.h> | 34 | #include <qdirectpainter_qws.h> |
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qtextstream.h> | 36 | #include <qtextstream.h> |
37 | #include <qfiledialog.h> | 37 | #include <qfiledialog.h> |
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | #include <qlayout.h> | 39 | #include <qlayout.h> |
40 | #include <qpainter.h> | 40 | #include <qpainter.h> |
41 | #include <qpushbutton.h> | 41 | #include <qpushbutton.h> |
42 | #include <qtimer.h> | 42 | #include <qtimer.h> |
43 | #include <qwhatsthis.h> | 43 | #include <qwhatsthis.h> |
44 | 44 | ||
45 | /* STD */ | 45 | /* STD */ |
46 | #include <time.h> | 46 | #include <time.h> |
47 | #include <stdio.h> | 47 | #include <stdio.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #if defined (__GNUC__) && (__GNUC__ < 3) | 50 | #if defined (__GNUC__) && (__GNUC__ < 3) |
51 | extern double round(double); | 51 | #define round qRound |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | using namespace Opie::Ui; | 54 | using namespace Opie::Ui; |
55 | using namespace Opie::Core; | 55 | using namespace Opie::Core; |
56 | extern "C" | 56 | extern "C" |
57 | 57 | ||
58 | { | 58 | { |
59 | void BenchFFT( void ); | 59 | void BenchFFT( void ); |
60 | double dhry_main( int ); | 60 | double dhry_main( int ); |
61 | } | 61 | } |
62 | 62 | ||
63 | #define DHRYSTONE_RUNS 20000000 | 63 | #define DHRYSTONE_RUNS 20000000 |
64 | #define TEST_DURATION 3 | 64 | #define TEST_DURATION 3 |
65 | 65 | ||
66 | #define BUFF_SIZE 8192 | 66 | #define BUFF_SIZE 8192 |
67 | #define FILE_SIZE 1024 * 1024 // 1Mb | 67 | #define FILE_SIZE 1024 * 1024 // 1Mb |
68 | 68 | ||
69 | //=========================================================================== | 69 | //=========================================================================== |
70 | 70 | ||
71 | class BenchmarkPaintWidget : public QWidget | 71 | class BenchmarkPaintWidget : public QWidget |
72 | { | 72 | { |
73 | public: | 73 | public: |
74 | BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever ) | 74 | BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever ) |
75 | { | 75 | { |
76 | resize( QApplication::desktop()->size() ); | 76 | resize( QApplication::desktop()->size() ); |
77 | show(); | 77 | show(); |
78 | p.begin( this ); | 78 | p.begin( this ); |
79 | }; | 79 | }; |
80 | 80 | ||
81 | ~BenchmarkPaintWidget() | 81 | ~BenchmarkPaintWidget() |
82 | { | 82 | { |
83 | p.end(); | 83 | p.end(); |
84 | hide(); | 84 | hide(); |
85 | }; | 85 | }; |
86 | 86 | ||
87 | QPainter p; | 87 | QPainter p; |
88 | }; | 88 | }; |
89 | 89 | ||
90 | //=========================================================================== | 90 | //=========================================================================== |
91 | 91 | ||
92 | BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags ) | 92 | BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags ) |
93 | : QWidget( parent, name, wFlags ) | 93 | : QWidget( parent, name, wFlags ) |
94 | { | 94 | { |
95 | 95 | ||
96 | setMinimumSize( 200, 150 ); | 96 | setMinimumSize( 200, 150 ); |
97 | 97 | ||
98 | QVBoxLayout* vb = new QVBoxLayout( this ); | 98 | QVBoxLayout* vb = new QVBoxLayout( this ); |
99 | vb->setSpacing( 4 ); | 99 | vb->setSpacing( 4 ); |
100 | vb->setMargin( 4 ); | 100 | vb->setMargin( 4 ); |
101 | 101 | ||
102 | tests = new OListView( this ); | 102 | tests = new OListView( this ); |
103 | QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests " | 103 | QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests " |
104 | "have been performed, and comparison values for one selected device. " | 104 | "have been performed, and comparison values for one selected device. " |
105 | "Use the checkboxes to define which tests you want to perform." ) ); | 105 | "Use the checkboxes to define which tests you want to perform." ) ); |
106 | tests->setMargin( 0 ); | 106 | tests->setMargin( 0 ); |
107 | tests->addColumn( tr( "Tests" ) ); | 107 | tests->addColumn( tr( "Tests" ) ); |
108 | tests->addColumn( tr( "Results" ) ); | 108 | tests->addColumn( tr( "Results" ) ); |
109 | tests->addColumn( tr( "Comparison" ) ); | 109 | tests->addColumn( tr( "Comparison" ) ); |
110 | tests->setShowSortIndicator( true ); | 110 | tests->setShowSortIndicator( true ); |
111 | 111 | ||
112 | test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox ); | 112 | test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox ); |
113 | test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox ); | 113 | test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox ); |
114 | test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox ); | 114 | test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox ); |
115 | test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox ); | 115 | test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox ); |
116 | test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox ); | 116 | test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox ); |
117 | test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox ); | 117 | test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox ); |
118 | test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox ); | 118 | test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox ); |
119 | 119 | ||
120 | test_alu->setText( 1, "n/a" ); | 120 | test_alu->setText( 1, "n/a" ); |
121 | test_fpu->setText( 1, "n/a" ); | 121 | test_fpu->setText( 1, "n/a" ); |
122 | test_txt->setText( 1, "n/a" ); | 122 | test_txt->setText( 1, "n/a" ); |
123 | test_gfx->setText( 1, "n/a" ); | 123 | test_gfx->setText( 1, "n/a" ); |
124 | test_ram->setText( 1, "n/a" ); | 124 | test_ram->setText( 1, "n/a" ); |
125 | test_sd->setText( 1, "n/a" ); | 125 | test_sd->setText( 1, "n/a" ); |
126 | test_cf->setText( 1, "n/a" ); | 126 | test_cf->setText( 1, "n/a" ); |
127 | 127 | ||
128 | test_alu->setText( 2, "n/a" ); | 128 | test_alu->setText( 2, "n/a" ); |
129 | test_fpu->setText( 2, "n/a" ); | 129 | test_fpu->setText( 2, "n/a" ); |
130 | test_txt->setText( 2, "n/a" ); | 130 | test_txt->setText( 2, "n/a" ); |
131 | test_gfx->setText( 2, "n/a" ); | 131 | test_gfx->setText( 2, "n/a" ); |
132 | test_ram->setText( 2, "n/a" ); | 132 | test_ram->setText( 2, "n/a" ); |
133 | test_sd->setText( 2, "n/a" ); | 133 | test_sd->setText( 2, "n/a" ); |
134 | test_cf->setText( 2, "n/a" ); | 134 | test_cf->setText( 2, "n/a" ); |
135 | 135 | ||
136 | startButton = new QPushButton( tr( "&Start Tests!" ), this ); | 136 | startButton = new QPushButton( tr( "&Start Tests!" ), this ); |
137 | QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) ); | 137 | QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) ); |
138 | connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) ); | 138 | connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) ); |
139 | vb->addWidget( tests, 2 ); | 139 | vb->addWidget( tests, 2 ); |
140 | 140 | ||
141 | QFile f( QPEApplication::qpeDir() + "/share/sysinfo/results" ); | 141 | QFile f( QPEApplication::qpeDir() + "/share/sysinfo/results" ); |
142 | if ( f.open( IO_ReadOnly ) ) | 142 | if ( f.open( IO_ReadOnly ) ) |
143 | { | 143 | { |
144 | machineCombo = new QComboBox( this ); | 144 | machineCombo = new QComboBox( this ); |
145 | QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) ); | 145 | QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) ); |
146 | 146 | ||
147 | QTextStream ts( &f ); | 147 | QTextStream ts( &f ); |
148 | while( !ts.eof() ) | 148 | while( !ts.eof() ) |
149 | { | 149 | { |
150 | QString machline = ts.readLine(); | 150 | QString machline = ts.readLine(); |
151 | qDebug( "sysinfo: parsing benchmark results for '%s'", (const char*) machline ); | 151 | qDebug( "sysinfo: parsing benchmark results for '%s'", (const char*) machline ); |
152 | QString resline = ts.readLine(); | 152 | QString resline = ts.readLine(); |
153 | machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) ); | 153 | machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) ); |
154 | machineCombo->insertItem( machline ); | 154 | machineCombo->insertItem( machline ); |
155 | } | 155 | } |
156 | 156 | ||
157 | QHBoxLayout* hb = new QHBoxLayout( vb ); | 157 | QHBoxLayout* hb = new QHBoxLayout( vb ); |
158 | hb->addWidget( new QLabel( tr( "Compare To:" ), this ) ); | 158 | hb->addWidget( new QLabel( tr( "Compare To:" ), this ) ); |
159 | hb->addWidget( machineCombo, 2 ); | 159 | hb->addWidget( machineCombo, 2 ); |
160 | connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) ); | 160 | connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) ); |
161 | } | 161 | } |
162 | 162 | ||
163 | vb->addWidget( startButton, 2 ); | 163 | vb->addWidget( startButton, 2 ); |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | BenchmarkInfo::~BenchmarkInfo() | 167 | BenchmarkInfo::~BenchmarkInfo() |
168 | {} | 168 | {} |
169 | 169 | ||
170 | 170 | ||
171 | void BenchmarkInfo::machineActivated( int index ) | 171 | void BenchmarkInfo::machineActivated( int index ) |
172 | { | 172 | { |
173 | QStringList* results = machines[ machineCombo->text( index ) ]; | 173 | QStringList* results = machines[ machineCombo->text( index ) ]; |
174 | if ( !results ) | 174 | if ( !results ) |
175 | { | 175 | { |
176 | qDebug( "sysinfo: no results available." ); | 176 | qDebug( "sysinfo: no results available." ); |
177 | return; | 177 | return; |
178 | } | 178 | } |
179 | QStringList::Iterator it = results->begin(); | 179 | QStringList::Iterator it = results->begin(); |
180 | test_alu->setText( 2, *(it++) ); | 180 | test_alu->setText( 2, *(it++) ); |
181 | test_fpu->setText( 2, *(it++) ); | 181 | test_fpu->setText( 2, *(it++) ); |
182 | test_txt->setText( 2, *(it++) ); | 182 | test_txt->setText( 2, *(it++) ); |
183 | test_gfx->setText( 2, *(it++) ); | 183 | test_gfx->setText( 2, *(it++) ); |
184 | test_ram->setText( 2, *(it++) ); | 184 | test_ram->setText( 2, *(it++) ); |
185 | test_sd->setText( 2, *(it++) ); | 185 | test_sd->setText( 2, *(it++) ); |
186 | test_cf->setText( 2, *(it++) ); | 186 | test_cf->setText( 2, *(it++) ); |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | void BenchmarkInfo::run() | 190 | void BenchmarkInfo::run() |
191 | { | 191 | { |
192 | startButton->setText( "> Don't touch! Running Tests! Don't touch! <" ); | 192 | startButton->setText( "> Don't touch! Running Tests! Don't touch! <" ); |
193 | qApp->processEvents(); | 193 | qApp->processEvents(); |
194 | QTime t; | 194 | QTime t; |
195 | 195 | ||
196 | if ( test_alu->isOn() ) | 196 | if ( test_alu->isOn() ) |
197 | { | 197 | { |
198 | int d = round( dhry_main( DHRYSTONE_RUNS ) ); | 198 | int d = round( dhry_main( DHRYSTONE_RUNS ) ); |
199 | test_alu->setText( 1, QString( "%1 dhrys" ).arg( QString::number( d ) ) ); | 199 | test_alu->setText( 1, QString( "%1 dhrys" ).arg( QString::number( d ) ) ); |
200 | test_alu->setOn( false ); | 200 | test_alu->setOn( false ); |
201 | } | 201 | } |
202 | 202 | ||
203 | if ( test_fpu->isOn() ) | 203 | if ( test_fpu->isOn() ) |
204 | { | 204 | { |
205 | t.start(); | 205 | t.start(); |
206 | BenchFFT(); | 206 | BenchFFT(); |
207 | test_fpu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) ); | 207 | test_fpu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) ); |
208 | test_fpu->setOn( false ); | 208 | test_fpu->setOn( false ); |
209 | } | 209 | } |
210 | 210 | ||
211 | if ( test_txt->isOn() ) | 211 | if ( test_txt->isOn() ) |
212 | { | 212 | { |
213 | int value = textRendering( TEST_DURATION ); | 213 | int value = textRendering( TEST_DURATION ); |
214 | test_txt->setText( 1, QString( "%1 chars/sec" ).arg( QString::number( value / TEST_DURATION ) ) ); | 214 | test_txt->setText( 1, QString( "%1 chars/sec" ).arg( QString::number( value / TEST_DURATION ) ) ); |
215 | test_txt->setOn( false ); | 215 | test_txt->setOn( false ); |
216 | } | 216 | } |
217 | 217 | ||
218 | if ( test_gfx->isOn() ) | 218 | if ( test_gfx->isOn() ) |
219 | { | 219 | { |
220 | int value = gfxRendering( TEST_DURATION ); | 220 | int value = gfxRendering( TEST_DURATION ); |
221 | test_gfx->setText( 1, QString( "%1 gops/sec" ).arg( QString::number( value / 4 / TEST_DURATION ) ) ); // 4 tests | 221 | test_gfx->setText( 1, QString( "%1 gops/sec" ).arg( QString::number( value / 4 / TEST_DURATION ) ) ); // 4 tests |
222 | test_gfx->setOn( false ); | 222 | test_gfx->setOn( false ); |
223 | } | 223 | } |
224 | 224 | ||
225 | if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA | 225 | if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA |
226 | { | 226 | { |
227 | performFileTest( "/tmp/benchmarkFile.dat", test_ram ); | 227 | performFileTest( "/tmp/benchmarkFile.dat", test_ram ); |
228 | } | 228 | } |
229 | 229 | ||
230 | if ( test_cf->isOn() ) | 230 | if ( test_cf->isOn() ) |
231 | { | 231 | { |
232 | OStorageInfo storage; | 232 | OStorageInfo storage; |
233 | performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf ); | 233 | performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf ); |
234 | } | 234 | } |
235 | 235 | ||
236 | if ( test_sd->isOn() ) | 236 | if ( test_sd->isOn() ) |
237 | { | 237 | { |
238 | OStorageInfo storage; | 238 | OStorageInfo storage; |
239 | performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd ); | 239 | performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd ); |
240 | } | 240 | } |
241 | 241 | ||
242 | startButton->setText( tr( "&Start Tests!" ) ); | 242 | startButton->setText( tr( "&Start Tests!" ) ); |
243 | } | 243 | } |
244 | 244 | ||
245 | 245 | ||
246 | int BenchmarkInfo::textRendering( int seconds ) | 246 | int BenchmarkInfo::textRendering( int seconds ) |
247 | { | 247 | { |
248 | QTime t; | 248 | QTime t; |
249 | t.start(); | 249 | t.start(); |
250 | int stop = t.elapsed() + seconds * 1000; | 250 | int stop = t.elapsed() + seconds * 1000; |
251 | 251 | ||
252 | int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; | 252 | int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; |
253 | int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; | 253 | int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; |
254 | int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; | 254 | int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; |
255 | const QString text( "Opie Benchmark Test" ); | 255 | const QString text( "Opie Benchmark Test" ); |
256 | 256 | ||
257 | int w = QApplication::desktop()->width(); | 257 | int w = QApplication::desktop()->width(); |
258 | int h = QApplication::desktop()->height(); | 258 | int h = QApplication::desktop()->height(); |
259 | 259 | ||
260 | srand( time( NULL ) ); | 260 | srand( time( NULL ) ); |
261 | 261 | ||
262 | BenchmarkPaintWidget bpw; | 262 | BenchmarkPaintWidget bpw; |
263 | 263 | ||
264 | int loops = 0; | 264 | int loops = 0; |
265 | 265 | ||
266 | while ( t.elapsed() < stop ) | 266 | while ( t.elapsed() < stop ) |
267 | { | 267 | { |
268 | int k = rand() % 9; | 268 | int k = rand() % 9; |
269 | int s = rand() % 100; | 269 | int s = rand() % 100; |
270 | bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); | 270 | bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); |
271 | bpw.p.setFont( QFont( "Vera", s ) ); | 271 | bpw.p.setFont( QFont( "Vera", s ) ); |
272 | bpw.p.drawText( rand() % w, rand() % h, text, text.length() ); | 272 | bpw.p.drawText( rand() % w, rand() % h, text, text.length() ); |
273 | ++loops; | 273 | ++loops; |
274 | } | 274 | } |
275 | 275 | ||
276 | return loops * text.length(); | 276 | return loops * text.length(); |
277 | } | 277 | } |
278 | 278 | ||
279 | int BenchmarkInfo::gfxRendering( int seconds ) | 279 | int BenchmarkInfo::gfxRendering( int seconds ) |
280 | { | 280 | { |
281 | int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; | 281 | int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; |
282 | int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; | 282 | int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; |
283 | int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; | 283 | int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; |
284 | 284 | ||
285 | int w = QApplication::desktop()->width(); | 285 | int w = QApplication::desktop()->width(); |
286 | int h = QApplication::desktop()->height(); | 286 | int h = QApplication::desktop()->height(); |
287 | 287 | ||
288 | srand( time( NULL ) ); | 288 | srand( time( NULL ) ); |
289 | 289 | ||
290 | BenchmarkPaintWidget bpw; | 290 | BenchmarkPaintWidget bpw; |
291 | 291 | ||
292 | QTime t; | 292 | QTime t; |
293 | t.start(); | 293 | t.start(); |
294 | int stop = t.elapsed() + seconds*1000; | 294 | int stop = t.elapsed() + seconds*1000; |
295 | int loops = 0; | 295 | int loops = 0; |
296 | 296 | ||
297 | while ( t.elapsed() < stop ) | 297 | while ( t.elapsed() < stop ) |
298 | { | 298 | { |
299 | int k = rand() % 9; | 299 | int k = rand() % 9; |
300 | bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); | 300 | bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); |
301 | bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h ); | 301 | bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h ); |
302 | ++loops; | 302 | ++loops; |
303 | } | 303 | } |
304 | 304 | ||
305 | t.restart(); | 305 | t.restart(); |
306 | stop = t.elapsed() + seconds*1000; | 306 | stop = t.elapsed() + seconds*1000; |
307 | 307 | ||
308 | while ( t.elapsed() < stop ) | 308 | while ( t.elapsed() < stop ) |
309 | { | 309 | { |
310 | int k = rand() % 9; | 310 | int k = rand() % 9; |
311 | bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); | 311 | bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); |
312 | bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 ); | 312 | bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 ); |
313 | ++loops; | 313 | ++loops; |
314 | } | 314 | } |
315 | 315 | ||
316 | QBrush br1; | 316 | QBrush br1; |
317 | br1.setStyle( SolidPattern ); | 317 | br1.setStyle( SolidPattern ); |
318 | t.restart(); | 318 | t.restart(); |
319 | stop = t.elapsed() + seconds*1000; | 319 | stop = t.elapsed() + seconds*1000; |
320 | 320 | ||
321 | while ( t.elapsed() < stop ) | 321 | while ( t.elapsed() < stop ) |
322 | { | 322 | { |
323 | int k = rand() % 9; | 323 | int k = rand() % 9; |
324 | br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); | 324 | br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); |
325 | bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 ); | 325 | bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 ); |
326 | ++loops; | 326 | ++loops; |
327 | } | 327 | } |
328 | 328 | ||
329 | QPixmap p = Resource::loadPixmap( "sysinfo/pattern" ); | 329 | QPixmap p = Resource::loadPixmap( "sysinfo/pattern" ); |
330 | t.restart(); | 330 | t.restart(); |
331 | stop = t.elapsed() + seconds*1000; | 331 | stop = t.elapsed() + seconds*1000; |
332 | 332 | ||
333 | while ( t.elapsed() < stop ) | 333 | while ( t.elapsed() < stop ) |
334 | { | 334 | { |
335 | bpw.p.drawPixmap( rand()%w, rand()%h, p ); | 335 | bpw.p.drawPixmap( rand()%w, rand()%h, p ); |
336 | ++loops; | 336 | ++loops; |
337 | } | 337 | } |
338 | 338 | ||
339 | return loops; | 339 | return loops; |
340 | 340 | ||
341 | } | 341 | } |
342 | 342 | ||
343 | void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item ) | 343 | void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item ) |
344 | { | 344 | { |
345 | QTime time; | 345 | QTime time; |
346 | time.start(); | 346 | time.start(); |
347 | if ( writeFile( fname ) && | 347 | if ( writeFile( fname ) && |
348 | readFile( fname ) ) | 348 | readFile( fname ) ) |
349 | { | 349 | { |
350 | QFile::remove( fname ); | 350 | QFile::remove( fname ); |
351 | item->setText( 1, QString( "%1 kb/sec" ).arg( QString::number( 1024.0 / ( time.elapsed() / 1000.0 ) ) ) ); | 351 | item->setText( 1, QString( "%1 kb/sec" ).arg( QString::number( 1024.0 / ( time.elapsed() / 1000.0 ) ) ) ); |
352 | item->setOn( false ); | 352 | item->setOn( false ); |
353 | } | 353 | } |
354 | else | 354 | else |
355 | { | 355 | { |
356 | item->setText( 1, tr( "error" ) ); | 356 | item->setText( 1, tr( "error" ) ); |
357 | } | 357 | } |
358 | } | 358 | } |
359 | 359 | ||
360 | char FileBuf[ BUFF_SIZE + 1 ]; | 360 | char FileBuf[ BUFF_SIZE + 1 ]; |
361 | 361 | ||
362 | bool BenchmarkInfo::writeFile( const QString& w_path ) | 362 | bool BenchmarkInfo::writeFile( const QString& w_path ) |
363 | { | 363 | { |
364 | int i; | 364 | int i; |
365 | int k; | 365 | int k; |
366 | int n; | 366 | int n; |
367 | int pos; | 367 | int pos; |
368 | int len; | 368 | int len; |
369 | char *data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 62 | 369 | char *data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 62 |
370 | 370 | ||
371 | 371 | ||
372 | // /*------------------------------------ | 372 | // /*------------------------------------ |
373 | int w_len; | 373 | int w_len; |
374 | 374 | ||
375 | QFile writeFile( w_path ); | 375 | QFile writeFile( w_path ); |
376 | srand( time( NULL ) ); | 376 | srand( time( NULL ) ); |
377 | 377 | ||
378 | for ( n = 0 ; n < 20 ; n++ ) | 378 | for ( n = 0 ; n < 20 ; n++ ) |
379 | { | 379 | { |
380 | if ( ! writeFile.open( IO_WriteOnly ) ) | 380 | if ( ! writeFile.open( IO_WriteOnly ) ) |
381 | { | 381 | { |
382 | writeFile.close(); | 382 | writeFile.close(); |
383 | writeFile.remove(); | 383 | writeFile.remove(); |
384 | return ( false ); | 384 | return ( false ); |
385 | } | 385 | } |
386 | // ------------------------------------------ sequential write | 386 | // ------------------------------------------ sequential write |
387 | for ( k = 0 ; k < 256 ; k++ ) | 387 | for ( k = 0 ; k < 256 ; k++ ) |
388 | { | 388 | { |
389 | n = rand() % 30; | 389 | n = rand() % 30; |
390 | memcpy( &FileBuf[ k * 32 ], &data[ n ], 32 ); | 390 | memcpy( &FileBuf[ k * 32 ], &data[ n ], 32 ); |
391 | } | 391 | } |
392 | 392 | ||
393 | for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) | 393 | for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) |
394 | { | 394 | { |
395 | w_len = writeFile.writeBlock( FileBuf, BUFF_SIZE ); | 395 | w_len = writeFile.writeBlock( FileBuf, BUFF_SIZE ); |
396 | if ( w_len != BUFF_SIZE ) | 396 | if ( w_len != BUFF_SIZE ) |
397 | { | 397 | { |
398 | writeFile.close(); | 398 | writeFile.close(); |
399 | writeFile.remove(); | 399 | writeFile.remove(); |
400 | return ( false ); | 400 | return ( false ); |
401 | } | 401 | } |
402 | writeFile.flush(); | 402 | writeFile.flush(); |
403 | } | 403 | } |
404 | // ------------------------------------------ random write | 404 | // ------------------------------------------ random write |
405 | for ( i = 0 ; i < 400 ; i++ ) | 405 | for ( i = 0 ; i < 400 ; i++ ) |
406 | { | 406 | { |
407 | len = rand() % 90 + 4000; | 407 | len = rand() % 90 + 4000; |
408 | for ( k = 0 ; k < 128 ; k++ ) | 408 | for ( k = 0 ; k < 128 ; k++ ) |
409 | { | 409 | { |
410 | n = rand() % 30; | 410 | n = rand() % 30; |
411 | memcpy( &FileBuf[ k * 8 ], &data[ n ], 32 ); | 411 | memcpy( &FileBuf[ k * 8 ], &data[ n ], 32 ); |
412 | } | 412 | } |
413 | pos = rand() % ( FILE_SIZE - BUFF_SIZE ); | 413 | pos = rand() % ( FILE_SIZE - BUFF_SIZE ); |
414 | 414 | ||
415 | writeFile.at( pos ); | 415 | writeFile.at( pos ); |
416 | w_len = writeFile.writeBlock( FileBuf, len ); | 416 | w_len = writeFile.writeBlock( FileBuf, len ); |
417 | if ( w_len != len ) | 417 | if ( w_len != len ) |
418 | { | 418 | { |
419 | writeFile.close(); | 419 | writeFile.close(); |
420 | writeFile.remove(); | 420 | writeFile.remove(); |
421 | return ( false ); | 421 | return ( false ); |
422 | } | 422 | } |
423 | writeFile.flush(); | 423 | writeFile.flush(); |
424 | } | 424 | } |
425 | writeFile.close(); | 425 | writeFile.close(); |
426 | } | 426 | } |
427 | return ( true ); | 427 | return ( true ); |
428 | 428 | ||
429 | } | 429 | } |
430 | 430 | ||
431 | 431 | ||
432 | bool BenchmarkInfo::readFile( const QString& r_path ) | 432 | bool BenchmarkInfo::readFile( const QString& r_path ) |
433 | { | 433 | { |
434 | int i; | 434 | int i; |
435 | int k; | 435 | int k; |
436 | int len; | 436 | int len; |
437 | int pos; | 437 | int pos; |
438 | int r_len; | 438 | int r_len; |
439 | 439 | ||
440 | QFile readFile( r_path ); | 440 | QFile readFile( r_path ); |
441 | srand( time( NULL ) ); | 441 | srand( time( NULL ) ); |
442 | 442 | ||
443 | for ( k = 0 ; k < 200 ; k++ ) | 443 | for ( k = 0 ; k < 200 ; k++ ) |
444 | { | 444 | { |
445 | if ( ! readFile.open( IO_ReadOnly ) ) | 445 | if ( ! readFile.open( IO_ReadOnly ) ) |
446 | { | 446 | { |
447 | readFile.remove(); | 447 | readFile.remove(); |
448 | return ( false ); | 448 | return ( false ); |
449 | } | 449 | } |
450 | // ------------------------------------------ sequential read | 450 | // ------------------------------------------ sequential read |
451 | readFile.at( 0 ); | 451 | readFile.at( 0 ); |
452 | for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) | 452 | for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) |
453 | { | 453 | { |
454 | readFile.at( i * BUFF_SIZE ); | 454 | readFile.at( i * BUFF_SIZE ); |
455 | r_len = readFile.readBlock( FileBuf, BUFF_SIZE ); | 455 | r_len = readFile.readBlock( FileBuf, BUFF_SIZE ); |
456 | if ( r_len != BUFF_SIZE ) | 456 | if ( r_len != BUFF_SIZE ) |
457 | { | 457 | { |
458 | readFile.close(); | 458 | readFile.close(); |
459 | readFile.remove(); | 459 | readFile.remove(); |
460 | return ( false ); | 460 | return ( false ); |
461 | } | 461 | } |
462 | } | 462 | } |
463 | // ------------------------------------------ random read | 463 | // ------------------------------------------ random read |
464 | for ( i = 0 ; i < 1000 ; i++ ) | 464 | for ( i = 0 ; i < 1000 ; i++ ) |
465 | { | 465 | { |
466 | len = rand() % 120 + 8; | 466 | len = rand() % 120 + 8; |
467 | pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE ); | 467 | pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE ); |
468 | readFile.at( pos ); | 468 | readFile.at( pos ); |
469 | r_len = readFile.readBlock( FileBuf, len ); | 469 | r_len = readFile.readBlock( FileBuf, len ); |
470 | if ( r_len != len ) | 470 | if ( r_len != len ) |
471 | { | 471 | { |
472 | readFile.close(); | 472 | readFile.close(); |
473 | readFile.remove(); | 473 | readFile.remove(); |
474 | return ( false ); | 474 | return ( false ); |
475 | } | 475 | } |
476 | } | 476 | } |
477 | readFile.close(); | 477 | readFile.close(); |
478 | } | 478 | } |
479 | return ( true ); | 479 | return ( true ); |
480 | } | 480 | } |