File indexing completed on 2024-03-24 15:42:35

0001 /*
0002     This file is part of LibSyndication.
0003     SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0006 */
0007 
0008 #include "documentsource.h"
0009 #include "feed.h"
0010 #include "parsercollection.h"
0011 #include "specificdocument.h"
0012 
0013 #include <QFile>
0014 #include <QString>
0015 #include <QStringList>
0016 #include <QTextStream>
0017 #include <QTime>
0018 
0019 #include <cstdio>
0020 #include <iostream>
0021 
0022 using namespace Syndication;
0023 
0024 int main(int argc, char **argv)
0025 {
0026     QString filename(argv[1]);
0027     QString arg1(argv[1]);
0028 
0029     /*
0030     if (filename == "--specific-format")
0031     {
0032         if (argc < 3)
0033         {
0034             printUsage("filename expected");
0035             return 1;
0036         }
0037         filename = QString(argv[2]);
0038         specificformat = true;
0039     }
0040     */
0041 
0042     int totalLength = 0;
0043     int numberOfFiles = 0;
0044 
0045     QStringList filenames;
0046 
0047     QFile input(arg1);
0048     input.open(QIODevice::ReadOnly);
0049     QTextStream stream(&input);
0050 
0051     while (!stream.atEnd()) {
0052         filenames += stream.readLine();
0053     }
0054     input.close();
0055 
0056     QTime time;
0057     time.start();
0058 
0059     for (const QString &filename : std::as_const(filenames)) {
0060         QFile f(filename);
0061 
0062         if (!f.open(QIODevice::ReadOnly)) {
0063             continue;
0064         }
0065 
0066         DocumentSource src(f.readAll(), "http://libsyndicationtest");
0067         f.close();
0068 
0069         FeedPtr ptr(Syndication::parse(src));
0070         if (ptr) {
0071             totalLength += src.size();
0072             ++numberOfFiles;
0073             QString dbg = ptr->debugInfo();
0074         }
0075 
0076         // std::cerr << "size of debug output: " << dbg.length() << std::endl;
0077     }
0078 
0079     int timeSpent = time.elapsed();
0080 
0081     std::cout << "total number of files: " << numberOfFiles << std::endl;
0082     std::cout << "total length of source (bytes): " << totalLength << std::endl;
0083     std::cout << "avg length (bytes): " << (double)totalLength / numberOfFiles << std::endl;
0084     std::cout << "time needed in total (ms): " << timeSpent << std::endl;
0085     std::cout << "source bytes per second: " << (totalLength * 1000.0) / timeSpent << std::endl;
0086     std::cout << "files per second: " << ((double)numberOfFiles * 1000) / timeSpent << std::endl;
0087     return 0;
0088 }