File indexing completed on 2024-05-12 16:35:54
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 "BenchmarkPointStorage.h" 0021 0022 #include "calligra_sheets_limits.h" 0023 0024 #include "PointStorage.h" 0025 0026 #include <QTest> 0027 #include <QUuid> 0028 0029 0030 using namespace Calligra::Sheets; 0031 0032 void PointStorageBenchmark::testInsertionPerformance_loadingLike() 0033 { 0034 PointStorage<int> storage; 0035 int col = 1; 0036 int row = 1; 0037 int cols = 100; 0038 int rows = 10000; 0039 QBENCHMARK { 0040 for (int r = row; r <= rows; ++r) { 0041 for (int c = col; c <= cols; c += 1) { 0042 storage.insert(c, r, c); 0043 } 0044 } 0045 } 0046 } 0047 0048 void PointStorageBenchmark::testInsertionPerformance_singular() 0049 { 0050 PointStorage<int> storage; 0051 QBENCHMARK { 0052 int col = 1 + rand() % 1000; 0053 int row = 1 + rand() % 1000; 0054 int cols = col + 1; 0055 int rows = row + 1; 0056 for (int r = row; r <= rows; ++r) { 0057 for (int c = col; c <= cols; c += 1) { 0058 storage.insert(c, r, c); 0059 } 0060 } 0061 } 0062 } 0063 0064 void PointStorageBenchmark::testLookupPerformance_data() 0065 { 0066 QTest::addColumn<int>("maxrow"); 0067 QTest::addColumn<int>("maxcol"); 0068 0069 QTest::newRow("very small") << 5 << 5; 0070 QTest::newRow("fit to screen") << 30 << 20; 0071 QTest::newRow("medium") << 100 << 100; 0072 QTest::newRow("large") << 1000 << 1000; 0073 QTest::newRow("typical data: more rows") << 10000 << 100; 0074 QTest::newRow("20 times larger") << 10000 << 2000; 0075 QTest::newRow("not really typical: more columns") << 100 << 10000; 0076 QTest::newRow("hopelessly large") << 8000 << 8000; 0077 QTest::newRow("some complete columns; KS_colMax-10, because of max lookup range of width 10 below") << 10 << 32757; 0078 QTest::newRow("some complete rows; KS_rowMax-10, because of max lookup range of height 10 below") << 32757 << 10; 0079 } 0080 0081 void PointStorageBenchmark::testLookupPerformance() 0082 { 0083 PointStorage<int> storage; 0084 QFETCH(int, maxrow); 0085 QFETCH(int, maxcol); 0086 0087 for (int r = 0; r < maxrow; ++r) { 0088 for (int c = 0; c < maxcol; ++c) { 0089 storage.m_data << c; 0090 storage.m_cols << (c + 1); 0091 } 0092 storage.m_rows << r*maxcol; 0093 } 0094 0095 // qDebug() << endl << qPrintable( storage.dump() ); 0096 0097 int v; 0098 int col = 0; 0099 int row = 0; 0100 int cols = 0; 0101 int rows = 0; 0102 QBENCHMARK { 0103 col = 1 + rand() % maxcol; 0104 row = 1 + rand() % maxrow; 0105 cols = col + 1 * (rand() % 10); 0106 rows = row + rand() % 10; 0107 for (int r = row; r <= rows; ++r) { 0108 for (int c = col; c <= cols; c += 1) { 0109 v = storage.lookup(c, r); 0110 } 0111 } 0112 } 0113 Q_UNUSED(v); //not fully unused but GCC thinks so, so let us just tell it so 0114 } 0115 0116 void PointStorageBenchmark::testInsertColumnsPerformance() 0117 { 0118 PointStorage<int> storage; 0119 for (int c = 0; c < KS_colMax; ++c) { 0120 storage.m_data << 1; 0121 storage.m_cols << 1; 0122 } 0123 storage.m_rows << 0; 0124 QBENCHMARK { 0125 storage.insertColumns(42, 3); 0126 } 0127 } 0128 0129 void PointStorageBenchmark::testDeleteColumnsPerformance() 0130 { 0131 PointStorage<int> storage; 0132 for (int c = 0; c < KS_colMax; ++c) { 0133 storage.m_data << 1; 0134 storage.m_cols << 1; 0135 } 0136 storage.m_rows << 0; 0137 QBENCHMARK { 0138 storage.removeColumns(42, 3); 0139 } 0140 } 0141 0142 void PointStorageBenchmark::testInsertRowsPerformance() 0143 { 0144 PointStorage<int> storage; 0145 for (int r = 0; r < KS_rowMax; ++r) { 0146 storage.m_data << 1; 0147 storage.m_cols << 1; 0148 storage.m_rows << r; 0149 } 0150 QBENCHMARK { 0151 storage.insertRows(42, 3); 0152 } 0153 } 0154 0155 void PointStorageBenchmark::testDeleteRowsPerformance() 0156 { 0157 PointStorage<int> storage; 0158 for (int r = 0; r < KS_rowMax; ++r) { 0159 storage.m_data << 1; 0160 storage.m_cols << 1; 0161 storage.m_rows << r; 0162 } 0163 QBENCHMARK { 0164 storage.removeRows(42, 3); 0165 } 0166 } 0167 0168 void PointStorageBenchmark::testShiftLeftPerformance() 0169 { 0170 PointStorage<int> storage; 0171 for (int c = 0; c < KS_colMax; ++c) { 0172 storage.m_data << 1; 0173 storage.m_cols << 1; 0174 } 0175 storage.m_rows << 0; 0176 QBENCHMARK { 0177 storage.removeShiftLeft(QRect(42, 1, 3, 1)); 0178 } 0179 } 0180 0181 void PointStorageBenchmark::testShiftRightPerformance() 0182 { 0183 PointStorage<int> storage; 0184 for (int c = 0; c < KS_colMax; ++c) { 0185 storage.m_data << 1; 0186 storage.m_cols << 1; 0187 } 0188 storage.m_rows << 0; 0189 QBENCHMARK { 0190 storage.insertShiftRight(QRect(42, 1, 3, 1)); 0191 } 0192 } 0193 0194 void PointStorageBenchmark::testShiftUpPerformance() 0195 { 0196 PointStorage<int> storage; 0197 for (int r = 0; r < KS_rowMax; ++r) { 0198 storage.m_data << 1; 0199 storage.m_cols << 1; 0200 storage.m_rows << r; 0201 } 0202 QBENCHMARK { 0203 storage.removeShiftUp(QRect(1, 42, 1, 3)); 0204 } 0205 } 0206 0207 void PointStorageBenchmark::testShiftDownPerformance() 0208 { 0209 PointStorage<int> storage; 0210 for (int r = 0; r < KS_rowMax; ++r) { 0211 storage.m_data << 1; 0212 storage.m_cols << 1; 0213 storage.m_rows << r; 0214 } 0215 storage.m_rows << 0; 0216 QBENCHMARK { 0217 storage.insertShiftDown(QRect(1, 42, 1, 3)); 0218 } 0219 } 0220 0221 void PointStorageBenchmark::testIterationPerformance_data() 0222 { 0223 QTest::addColumn<int>("maxrow"); 0224 QTest::addColumn<int>("maxcol"); 0225 0226 QTest::newRow("very small") << 5 << 5; 0227 QTest::newRow("fit to screen") << 30 << 20; 0228 QTest::newRow("medium") << 100 << 100; 0229 QTest::newRow("large") << 1000 << 1000; 0230 QTest::newRow("typical data: more rows") << 10000 << 100; 0231 QTest::newRow("20 times larger") << 10000 << 2000; 0232 QTest::newRow("not really typical: more columns") << 100 << 10000; 0233 QTest::newRow("hopelessly large") << 8000 << 8000; 0234 #if 0 0235 QTest::newRow("some complete columns; KS_colMax-10, because of max lookup range of width 10 below") << 10 << 32757; 0236 QTest::newRow("some complete rows; KS_rowMax-10, because of max lookup range of height 10 below") << 32757 << 10; 0237 #endif 0238 } 0239 0240 void PointStorageBenchmark::testIterationPerformance() 0241 { 0242 PointStorage<int> storage; 0243 0244 QFETCH(int, maxrow); 0245 QFETCH(int, maxcol); 0246 0247 storage.clear(); 0248 for (int r = 0; r < maxrow; ++r) { 0249 for (int c = 0; c < maxcol; ++c) { 0250 storage.m_data << c; 0251 storage.m_cols << (c + 1); 0252 } 0253 storage.m_rows << r*maxcol; 0254 } 0255 0256 // qDebug() << endl << qPrintable( storage.dump() ); 0257 QString prefix = QString("%1 x %2").arg(maxrow).arg(maxcol); 0258 0259 int v; 0260 QBENCHMARK { 0261 for (int i = 0; i < storage.count(); ++i) { 0262 v = storage.data(i); 0263 } 0264 } 0265 Q_UNUSED(v); //Not fully unused, but GCC thinks so 0266 } 0267 0268 QTEST_MAIN(PointStorageBenchmark)