File indexing completed on 2024-04-28 03:57:07

0001 #include <QApplication>
0002 #include <QCommandLineOption>
0003 #include <QCommandLineParser>
0004 
0005 #include <KMainWindow>
0006 #include <kateconfig.h>
0007 #include <katedocument.h>
0008 #include <katesearchbar.h>
0009 #include <kateview.h>
0010 
0011 static constexpr int lines = 100000;
0012 
0013 int main(int argc, char *argv[])
0014 {
0015     QApplication app(argc, argv);
0016 
0017     QCommandLineParser p;
0018     p.setApplicationDescription(QStringLiteral("Performance benchmark for search"));
0019     p.addHelpOption();
0020     // number of iterations
0021     QCommandLineOption iterOpt(QStringLiteral("i"),
0022                                QStringLiteral("Number of lines of text in which search will happen"),
0023                                QStringLiteral("iters"),
0024                                QStringLiteral("0"));
0025     p.addOption(iterOpt);
0026 
0027     p.process(app);
0028     bool ok = false;
0029     int iters = p.value(iterOpt).toInt(&ok);
0030 
0031     KMainWindow *w = new KMainWindow;
0032     w->activateWindow();
0033 
0034     KTextEditor::DocumentPrivate doc;
0035     KTextEditor::ViewPrivate view(&doc, nullptr);
0036     KateViewConfig config(&view);
0037     KateSearchBar bar(true, &view, &config);
0038 
0039     int linesInText = ok ? (iters > 0 ? iters : lines) : lines;
0040 
0041     QStringList l;
0042     l.reserve(linesInText);
0043     for (int i = 0; i < linesInText; ++i) {
0044         l.append(QStringLiteral("This is a long long long sentence."));
0045     }
0046     doc.setText(l);
0047 
0048     QObject::connect(&bar, &KateSearchBar::findOrReplaceAllFinished, [&w]() {
0049         w->close();
0050     });
0051 
0052     bar.setSearchMode(KateSearchBar::SearchMode::MODE_PLAIN_TEXT);
0053     bar.setSearchPattern(QStringLiteral("long"));
0054 
0055     bar.findAll();
0056 
0057     return app.exec();
0058 }