File: benchmark.cpp

package info (click to toggle)
syndication 1%3A5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,072 kB
  • sloc: xml: 14,780; cpp: 9,693; ruby: 60; makefile: 7
file content (88 lines) | stat: -rw-r--r-- 2,218 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
    This file is part of LibSyndication.
    SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
*/

#include "documentsource.h"
#include "feed.h"
#include "parsercollection.h"
#include "specificdocument.h"

#include <QFile>
#include <QString>
#include <QStringList>
#include <QTextStream>
#include <QTime>

#include <cstdio>
#include <iostream>

using namespace Syndication;

int main(int argc, char **argv)
{
    QString filename(argv[1]);
    QString arg1(argv[1]);

    /*
    if (filename == "--specific-format")
    {
        if (argc < 3)
        {
            printUsage("filename expected");
            return 1;
        }
        filename = QString(argv[2]);
        specificformat = true;
    }
    */

    int totalLength = 0;
    int numberOfFiles = 0;

    QStringList filenames;

    QFile input(arg1);
    input.open(QIODevice::ReadOnly);
    QTextStream stream(&input);

    while (!stream.atEnd()) {
        filenames += stream.readLine();
    }
    input.close();

    QTime time;
    time.start();

    for (const QString &filename : std::as_const(filenames)) {
        QFile f(filename);

        if (!f.open(QIODevice::ReadOnly)) {
            continue;
        }

        DocumentSource src(f.readAll(), "http://libsyndicationtest");
        f.close();

        FeedPtr ptr(Syndication::parse(src));
        if (ptr) {
            totalLength += src.size();
            ++numberOfFiles;
            QString dbg = ptr->debugInfo();
        }

        // std::cerr << "size of debug output: " << dbg.length() << std::endl;
    }

    int timeSpent = time.elapsed();

    std::cout << "total number of files: " << numberOfFiles << std::endl;
    std::cout << "total length of source (bytes): " << totalLength << std::endl;
    std::cout << "avg length (bytes): " << (double)totalLength / numberOfFiles << std::endl;
    std::cout << "time needed in total (ms): " << timeSpent << std::endl;
    std::cout << "source bytes per second: " << (totalLength * 1000.0) / timeSpent << std::endl;
    std::cout << "files per second: " << ((double)numberOfFiles * 1000) / timeSpent << std::endl;
    return 0;
}