mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-04 16:25:27 +08:00
qt 6.5.1 original
This commit is contained in:
13
tests/benchmarks/corelib/json/CMakeLists.txt
Normal file
13
tests/benchmarks/corelib/json/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_bench_qtjson Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qtjson
|
||||
SOURCES
|
||||
tst_bench_qtjson.cpp
|
||||
LIBRARIES
|
||||
Qt::Test
|
||||
)
|
19
tests/benchmarks/corelib/json/numbers.json
Normal file
19
tests/benchmarks/corelib/json/numbers.json
Normal file
@ -0,0 +1,19 @@
|
||||
[
|
||||
{
|
||||
"integer": 1234567890,
|
||||
"real": -9876.543210,
|
||||
"e": 0.123456789e-12,
|
||||
"E": 1.234567890E+34,
|
||||
"": 23456789012E66,
|
||||
"zero": 0,
|
||||
"one": 1
|
||||
},
|
||||
[
|
||||
-1234567890,
|
||||
-1234567890,
|
||||
-1234567890,
|
||||
1234567890,
|
||||
1234567890,
|
||||
1234567890
|
||||
]
|
||||
]
|
66
tests/benchmarks/corelib/json/test.json
Normal file
66
tests/benchmarks/corelib/json/test.json
Normal file
File diff suppressed because one or more lines are too long
122
tests/benchmarks/corelib/json/tst_bench_qtjson.cpp
Normal file
122
tests/benchmarks/corelib/json/tst_bench_qtjson.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QTest>
|
||||
#include <QVariantMap>
|
||||
#include <qjsondocument.h>
|
||||
#include <qjsonobject.h>
|
||||
|
||||
class BenchmarkQtJson: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BenchmarkQtJson(QObject *parent = nullptr);
|
||||
|
||||
private Q_SLOTS:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void parseNumbers();
|
||||
void parseJson();
|
||||
void parseJsonToVariant();
|
||||
|
||||
void jsonObjectInsert();
|
||||
void variantMapInsert();
|
||||
};
|
||||
|
||||
BenchmarkQtJson::BenchmarkQtJson(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::initTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::cleanupTestCase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::parseNumbers()
|
||||
{
|
||||
QString testFile = QFINDTESTDATA("numbers.json");
|
||||
QVERIFY2(!testFile.isEmpty(), "cannot find test file numbers.json!");
|
||||
QFile file(testFile);
|
||||
file.open(QFile::ReadOnly);
|
||||
QByteArray testJson = file.readAll();
|
||||
|
||||
QBENCHMARK {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(testJson);
|
||||
QJsonObject object = doc.object();
|
||||
}
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::parseJson()
|
||||
{
|
||||
QString testFile = QFINDTESTDATA("test.json");
|
||||
QVERIFY2(!testFile.isEmpty(), "cannot find test file test.json!");
|
||||
QFile file(testFile);
|
||||
file.open(QFile::ReadOnly);
|
||||
QByteArray testJson = file.readAll();
|
||||
|
||||
QBENCHMARK {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(testJson);
|
||||
QJsonObject object = doc.object();
|
||||
}
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::parseJsonToVariant()
|
||||
{
|
||||
QString testFile = QFINDTESTDATA("test.json");
|
||||
QVERIFY2(!testFile.isEmpty(), "cannot find test file test.json!");
|
||||
QFile file(testFile);
|
||||
file.open(QFile::ReadOnly);
|
||||
QByteArray testJson = file.readAll();
|
||||
|
||||
QBENCHMARK {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(testJson);
|
||||
QVariant v = doc.toVariant();
|
||||
}
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::jsonObjectInsert()
|
||||
{
|
||||
QJsonObject object;
|
||||
QString test(QStringLiteral("testString"));
|
||||
QJsonValue value(1.5);
|
||||
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; i++)
|
||||
object.insert("testkey_" + QString::number(i), value);
|
||||
}
|
||||
}
|
||||
|
||||
void BenchmarkQtJson::variantMapInsert()
|
||||
{
|
||||
QVariantMap object;
|
||||
QString test(QStringLiteral("testString"));
|
||||
QVariant variantValue(1.5);
|
||||
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; i++)
|
||||
object.insert("testkey_" + QString::number(i), variantValue);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(BenchmarkQtJson)
|
||||
#include "tst_bench_qtjson.moc"
|
||||
|
Reference in New Issue
Block a user