File indexing completed on 2024-05-12 16:35:54

0001 /* This file is part of the KDE project
0002    Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003 
0004    This program is free software; you can redistribute it and/or modify
0005    it under the terms of the GNU General Public License as published by
0006    the Free Software Foundation; either version 2 of the License, or
0007    (at your option) any later version.
0008 
0009    This program 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
0012    GNU General Public License for more details.
0013 
0014    You should have received a copy of the GNU General Public License
0015    along with this program; if not, write to the Free Software
0016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
0017    MA  02110-1301  USA
0018 */
0019 #include "BenchmarkRTree.h"
0020 
0021 // #include "rtree.h"
0022 #include "RTree.h"
0023 
0024 #include <QTest>
0025 
0026 using namespace std;
0027 using namespace Calligra::Sheets;
0028 
0029 void RTreeBenchmark::init()
0030 {
0031     RTree<double> tree;
0032     m_tree = tree;
0033     // insert some data in the RTree
0034     const int max_x = 100;
0035     const int step_x = 1;
0036     const int max_y = 1000;
0037     const int step_y = 1;
0038     for (int y = 1; y <= max_y; y += step_y) { // equals row insertion into table
0039         for (int x = 1; x <= max_x; x += step_x) { // equals cell insertion into row
0040             m_tree.insert(QRect(x, y, step_x, step_y), 42);
0041         }
0042     }
0043 }
0044 
0045 void RTreeBenchmark::cleanup()
0046 {
0047 }
0048 
0049 void RTreeBenchmark::testInsertionPerformance()
0050 {
0051     // reset tree for this test
0052     RTree<double> tree;
0053     m_tree = tree;
0054 
0055     const int max_x = 100;
0056     const int step_x = 1;
0057     const int max_y = 1000;
0058     const int step_y = 1;
0059 
0060     QBENCHMARK {
0061         for (int y = 1; y <= max_y; y += step_y) { // equals row insertion into table
0062             for (int x = 1; x <= max_x; x += step_x) { // equals cell insertion into row
0063                 m_tree.insert(QRect(x, y, step_x, step_y), 42);
0064             }
0065         }
0066     }
0067 }
0068 
0069 void RTreeBenchmark::testRowInsertionPerformance()
0070 {
0071     QBENCHMARK {
0072         m_tree.insertRows(1, 5);
0073     }
0074 }
0075 
0076 void RTreeBenchmark::testColumnInsertionPerformance()
0077 {
0078     QBENCHMARK {
0079         m_tree.insertColumns(1, 5);
0080     }
0081 }
0082 
0083 void RTreeBenchmark::testRowDeletionPerformance()
0084 {
0085     QBENCHMARK {
0086         m_tree.removeRows(1, 5);
0087     }
0088 }
0089 
0090 void RTreeBenchmark::testColumnDeletionPerformance()
0091 {
0092     QBENCHMARK {
0093         m_tree.removeColumns(1, 5);
0094     }
0095 }
0096 
0097 void RTreeBenchmark::testLookupPerformance()
0098 {
0099     int counter = 0;
0100     const int max_x = 100;
0101     const int step_x = 1;
0102     const int max_y = 1000;
0103     const int step_y = 1;
0104     QBENCHMARK {
0105         for (int y = 1; y <= max_y; y += step_y) {
0106             for (int x = 1; x <= max_x; x += step_x) {
0107                 if (!m_tree.contains(QPoint(x, y)).isEmpty()) counter++;
0108             }
0109         }
0110     }
0111 }
0112 
0113 QTEST_MAIN(RTreeBenchmark)