File indexing completed on 2024-04-28 04:35:52
0001 /* 0002 * This file is part of KDevelop 0003 * Copyright (C) 2012-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 0020 // Qt + KDE 0021 #include <QtTest/QtTest> 0022 0023 // Ruby 0024 #include <duchain/helpers.h> 0025 #include <duchain/editorintegrator.h> 0026 #include <duchain/builders/declarationbuilder.h> 0027 #include <duchain/tests/benchmarks.h> 0028 #include <parser/parser.h> 0029 0030 0031 QTEST_MAIN(ruby::Benchmarks) 0032 0033 using namespace KDevelop; 0034 namespace ruby 0035 { 0036 0037 Benchmarks::Benchmarks() 0038 { 0039 /* There's nothing to do here */ 0040 } 0041 0042 const QByteArray Benchmarks::getBuiltinsFile() 0043 { 0044 const QString &fileName = builtinsFile().str(); 0045 QFile file(fileName); 0046 bool opened = file.open(QIODevice::ReadOnly); 0047 Q_ASSERT(opened); 0048 const QByteArray &txt = file.readAll(); 0049 file.close(); 0050 return txt; 0051 } 0052 0053 void Benchmarks::parser() 0054 { 0055 const QByteArray &contents = getBuiltinsFile(); 0056 0057 QBENCHMARK { 0058 Parser parser; 0059 parser.setContents(contents); 0060 parser.parse(); 0061 } 0062 } 0063 0064 void Benchmarks::declarationBuilder() 0065 { 0066 const QByteArray &contents = getBuiltinsFile(); 0067 Parser parser(builtinsFile(), contents); 0068 Ast * ast = parser.parse(); 0069 EditorIntegrator editor; 0070 editor.setParseSession(&parser); 0071 0072 QBENCHMARK { 0073 DeclarationBuilder builder(&editor); 0074 ReferencedTopDUContext top = builder.build(builtinsFile(), ast); 0075 } 0076 } 0077 0078 } 0079