File indexing completed on 2024-05-12 16:35:53
0001 /* This file is part of the KDE project 0002 Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "BenchmarkCluster.h" 0021 0022 #include "BenchmarkHelper.h" 0023 #include "Cluster.h" 0024 #include "Global.h" 0025 0026 #include <QTest> 0027 0028 using namespace KSpread; 0029 class Cell; 0030 0031 void ClusterBenchmark::testInsertionPerformance() 0032 { 0033 Cluster storage; 0034 Cell* cell = 0; 0035 qDebug() << "measuring loading-like insertion..."; 0036 Time::tval start = 0; 0037 Time::tval ticks = 0; 0038 int col = 1; 0039 int row = 1; 0040 int cols = 100; 0041 int rows = 10000; 0042 long counter = 0; 0043 start = Time::stamp(); 0044 for (int r = row; r <= rows; ++r) { 0045 for (int c = col; c <= cols; c += 1) { 0046 storage.insert(cell, c, r); 0047 counter += 1; 0048 } 0049 } 0050 ticks = Time::elapsed(start); 0051 qDebug() << qPrintable(Time::printAverage(ticks, counter)); 0052 0053 qDebug() << "measuring random singular insertion..."; 0054 storage.clear(); 0055 counter = 0; 0056 while (counter < Time::iterations) { 0057 col = 1 + rand() % 1000; 0058 row = 1 + rand() % 1000; 0059 cols = col + 1; 0060 rows = row + 1; 0061 start = Time::stamp(); 0062 for (int r = row; r <= rows; ++r) { 0063 for (int c = col; c <= cols && counter < Time::iterations; c += 1) { 0064 storage.insert(cell, c, r); 0065 counter += 1; 0066 } 0067 } 0068 ticks += Time::elapsed(start); 0069 } 0070 qDebug() << qPrintable(Time::printAverage(ticks, counter)); 0071 } 0072 0073 void ClusterBenchmark::testLookupPerformance() 0074 { 0075 // row x column 0076 const int scenarios[] = { 0077 #if 1 0078 1000, 1000 // large 0079 #else 0080 5, 5, // very small 0081 30, 20, // fit to screen 0082 100, 100, // medium 0083 1000, 1000, // large 0084 10000, 100, // typical data: more rows 0085 10000, 2000, // and 20 times larger 0086 100, 10000, // not really typical: more columns 0087 8000, 8000 // hopelessly large 0088 #endif 0089 }; 0090 0091 Cluster storage; 0092 Cell* cell = 0; 0093 0094 for (uint sc = 0; sc < sizeof(scenarios) / sizeof(scenarios[0]) / 2; sc++) { 0095 int maxrow = scenarios[sc*2]; 0096 int maxcol = scenarios[sc*2+1]; 0097 0098 storage.clear(); 0099 #if 0 0100 for (int r = 0; r < maxrow; ++r) { 0101 for (int c = 0; c < maxcol; ++c) { 0102 storage.insert(cell, c, r); 0103 } 0104 } 0105 #else 0106 storage.insert(cell, 1, 1); 0107 storage.insert(cell, maxcol / 2, maxrow / 2); 0108 storage.insert(cell, maxcol / 3, maxrow / 3); 0109 storage.insert(cell, maxcol, maxrow); 0110 #endif 0111 // qDebug() << endl << qPrintable( storage.dump() ); 0112 QString prefix = QString("%1 x %2").arg(maxrow).arg(maxcol); 0113 qDebug() << "start measuring..." << prefix; 0114 0115 Time::tval start = 0; 0116 Time::tval ticks = 0; 0117 Cell* v; 0118 int col = 0; 0119 int row = 0; 0120 int cols = 0; 0121 int rows = 0; 0122 long counter = 0; 0123 while (counter < Time::iterations) { 0124 col = 1 + rand() % maxcol; 0125 row = 1 + rand() % maxrow; 0126 cols = col + 1 * (rand() % 10); 0127 rows = row + rand() % 10; 0128 start = Time::stamp(); 0129 for (int r = row; r <= rows && counter < Time::iterations; ++r) { 0130 for (int c = col; c <= cols && counter < Time::iterations; c += 1) { 0131 v = storage.lookup(c, r); 0132 counter += 1; 0133 } 0134 } 0135 ticks += Time::elapsed(start); 0136 } 0137 qDebug() << qPrintable(Time::printAverage(ticks, counter, prefix)); 0138 } 0139 } 0140 0141 void ClusterBenchmark::testInsertColumnsPerformance() 0142 { 0143 Cluster storage; 0144 Cell* cell = 0; 0145 for (int c = 1; c <= KS_colMax; ++c) 0146 storage.insert(cell, c, 1); 0147 qDebug() << "start measuring..."; 0148 0149 Time::tval start = Time::stamp(); 0150 for (int i = 1; i < 100; ++i) 0151 storage.insertColumn(250); // near a cluster border 0152 qDebug() << qPrintable(Time::printAverage(Time::elapsed(start), 100)); 0153 } 0154 0155 void ClusterBenchmark::testDeleteColumnsPerformance() 0156 { 0157 Cluster storage; 0158 Cell* cell = 0; 0159 for (int c = 1; c <= KS_colMax; ++c) 0160 storage.insert(cell, c, 1); 0161 qDebug() << "start measuring..."; 0162 0163 Time::tval start = Time::stamp(); 0164 for (int i = 1; i < 100; ++i) 0165 storage.removeColumn(250); // near a cluster border 0166 qDebug() << qPrintable(Time::printAverage(Time::elapsed(start), 100)); 0167 } 0168 0169 void ClusterBenchmark::testInsertRowsPerformance() 0170 { 0171 Cluster storage; 0172 Cell* cell = 0; 0173 for (int r = 1; r <= KS_rowMax; ++r) 0174 storage.insert(cell, 1, r); 0175 qDebug() << "start measuring..."; 0176 0177 Time::tval start = Time::stamp(); 0178 for (int i = 1; i < 100; ++i) 0179 storage.insertRow(250); // near a cluster border 0180 qDebug() << qPrintable(Time::printAverage(Time::elapsed(start), 100)); 0181 } 0182 0183 void ClusterBenchmark::testDeleteRowsPerformance() 0184 { 0185 Cluster storage; 0186 Cell* cell = 0; 0187 for (int r = 1; r <= KS_rowMax; ++r) 0188 storage.insert(cell, 1, r); 0189 qDebug() << "start measuring..."; 0190 0191 Time::tval start = Time::stamp(); 0192 for (int i = 1; i < 100; ++i) 0193 storage.removeRow(250); // near a cluster border 0194 qDebug() << qPrintable(Time::printAverage(Time::elapsed(start), 100)); 0195 } 0196 0197 void ClusterBenchmark::testShiftLeftPerformance() 0198 { 0199 Cluster storage; 0200 Cell* cell = 0; 0201 for (int c = 1; c <= KS_colMax; ++c) 0202 storage.insert(cell, c, 1); 0203 qDebug() << "start measuring..."; 0204 0205 Time::tval start = Time::stamp(); 0206 for (int i = 1; i < 1000; ++i) 0207 storage.removeShiftLeft(QPoint(42, 1)); 0208 qDebug() << qPrintable(Time::printAverage(Time::elapsed(start), 1000)); 0209 } 0210 0211 void ClusterBenchmark::testShiftRightPerformance() 0212 { 0213 Cluster storage; 0214 Cell* cell = 0; 0215 for (int c = 1; c <= KS_colMax; ++c) 0216 storage.insert(cell, c, 1); 0217 qDebug() << "start measuring..."; 0218 0219 Time::tval start = Time::stamp(); 0220 for (int i = 1; i < 1000; ++i) 0221 storage.insertShiftRight(QPoint(42, 1)); 0222 qDebug() << qPrintable(Time::printAverage(Time::elapsed(start), 1000)); 0223 } 0224 0225 void ClusterBenchmark::testShiftUpPerformance() 0226 { 0227 Cluster storage; 0228 Cell* cell = 0; 0229 for (int r = 1; r <= KS_rowMax; ++r) 0230 storage.insert(cell, 1, r); 0231 qDebug() << "start measuring..."; 0232 0233 Time::tval start = Time::stamp(); 0234 for (int i = 1; i < 1000; ++i) 0235 storage.removeShiftUp(QPoint(1, 42)); 0236 qDebug() << qPrintable(Time::printAverage(Time::elapsed(start), 1000)); 0237 } 0238 0239 void ClusterBenchmark::testShiftDownPerformance() 0240 { 0241 Cluster storage; 0242 Cell* cell = 0; 0243 for (int r = 1; r <= KS_rowMax; ++r) 0244 storage.insert(cell, 1, r); 0245 qDebug() << "start measuring..."; 0246 0247 Time::tval start = Time::stamp(); 0248 for (int i = 1; i < 1000; ++i) 0249 storage.insertShiftDown(QPoint(1, 42)); 0250 qDebug() << qPrintable(Time::printAverage(Time::elapsed(start), 1000)); 0251 } 0252 0253 0254 0255 QTEST_MAIN(ClusterBenchmark)