Initial commit.
This commit is contained in:
38
3rdparty/qjson/tests/benchmarks/CMakeLists.txt
vendored
Normal file
38
3rdparty/qjson/tests/benchmarks/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
##### Probably don't want to edit below this line #####
|
||||
|
||||
SET( QT_USE_QTTEST TRUE )
|
||||
|
||||
INCLUDE(AddFileDependencies)
|
||||
|
||||
# Include the library include directories, and the current build directory (moc)
|
||||
INCLUDE_DIRECTORIES(
|
||||
../../include
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
SET( UNIT_TESTS
|
||||
parsingbenchmark
|
||||
qlocalevsstrtod_l
|
||||
)
|
||||
|
||||
# Build the tests
|
||||
FOREACH(test ${UNIT_TESTS})
|
||||
MESSAGE(STATUS "Building ${test}")
|
||||
ADD_EXECUTABLE(
|
||||
${test}
|
||||
${test}.cpp
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(
|
||||
${test}
|
||||
${QT_LIBRARIES}
|
||||
${TEST_LIBRARIES}
|
||||
qjson${QJSON_SUFFIX}
|
||||
)
|
||||
if (QJSON_TEST_OUTPUT STREQUAL "xml")
|
||||
# produce XML output
|
||||
add_test( ${test} ${test} -xml -o ${test}.tml )
|
||||
else (QJSON_TEST_OUTPUT STREQUAL "xml")
|
||||
add_test( ${test} ${test} )
|
||||
endif (QJSON_TEST_OUTPUT STREQUAL "xml")
|
||||
ENDFOREACH()
|
||||
55
3rdparty/qjson/tests/benchmarks/parsingbenchmark.cpp
vendored
Normal file
55
3rdparty/qjson/tests/benchmarks/parsingbenchmark.cpp
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/* This file is part of QJson
|
||||
*
|
||||
* Copyright (C) 2014 Sune Vuorela <sune@ange.dk>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QJson/Parser>
|
||||
#include <QJson/Serializer>
|
||||
#include <QtTest/QTest>
|
||||
#include <QFile>
|
||||
|
||||
class ParsingBenchmark: public QObject {
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void benchmark();
|
||||
};
|
||||
|
||||
void ParsingBenchmark::benchmark() {
|
||||
QString path = QFINDTESTDATA("largefile.json");
|
||||
|
||||
QVERIFY(QFile::exists(path));
|
||||
|
||||
QFile f(path);
|
||||
QVERIFY(f.open(QIODevice::ReadOnly));
|
||||
|
||||
QByteArray data = f.readAll();
|
||||
|
||||
QVariant result;
|
||||
|
||||
QJson::Parser parser;
|
||||
QBENCHMARK {
|
||||
result = parser.parse(data);
|
||||
}
|
||||
|
||||
Q_UNUSED(result);
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(ParsingBenchmark)
|
||||
|
||||
#include "parsingbenchmark.moc"
|
||||
70
3rdparty/qjson/tests/benchmarks/qlocalevsstrtod_l.cpp
vendored
Normal file
70
3rdparty/qjson/tests/benchmarks/qlocalevsstrtod_l.cpp
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/* This file is part of QJson
|
||||
*
|
||||
* Copyright (C) 2014 Sune Vuorela <sune@ange.dk>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QtTest>
|
||||
#include <locale.h>
|
||||
|
||||
class QLocaleVsStrtod_l : public QObject {
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void benchmark();
|
||||
void benchmark_data();
|
||||
|
||||
};
|
||||
|
||||
void QLocaleVsStrtod_l::benchmark() {
|
||||
QFETCH(bool, useQLocale);
|
||||
QList<char*> l;
|
||||
l << strdup("0.123") << strdup("0.947834") << strdup("8.8373") << strdup("884.82921");
|
||||
|
||||
double result;
|
||||
|
||||
if(useQLocale) {
|
||||
QLocale c(QLocale::C);
|
||||
QBENCHMARK {
|
||||
Q_FOREACH(const char* str, l) {
|
||||
result = c.toDouble(QString(str));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
locale_t c = newlocale(LC_NUMERIC_MASK, "C", NULL);
|
||||
QBENCHMARK {
|
||||
Q_FOREACH(const char* str, l) {
|
||||
result = strtod_l(str, NULL, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Q_FOREACH(char* str, l) {
|
||||
free(str);
|
||||
}
|
||||
}
|
||||
|
||||
void QLocaleVsStrtod_l::benchmark_data() {
|
||||
QTest::addColumn<bool>("useQLocale");
|
||||
|
||||
QTest::newRow("using QLocale") << true;
|
||||
QTest::newRow("using strtod_l") << false;
|
||||
}
|
||||
|
||||
QTEST_MAIN(QLocaleVsStrtod_l);
|
||||
#include "qlocalevsstrtod_l.moc"
|
||||
Reference in New Issue
Block a user