Commit ec059fd9 authored by Igor Kushnir's avatar Igor Kushnir

Move benchmarks from test_indexedstring to bench_indexedstring

parent 3f7a8332
......@@ -9,7 +9,10 @@ remove_definitions(
if(BUILD_BENCHMARKS)
ecm_add_test(bench_itemrepository.cpp LINK_LIBRARIES
LINK_LIBRARIES Qt5::Test KDev::Serialization KDev::Tests)
ecm_add_test(bench_indexedstring.cpp LINK_LIBRARIES
LINK_LIBRARIES Qt5::Test KDev::Serialization KDev::Tests)
set_tests_properties(bench_itemrepository PROPERTIES TIMEOUT 30)
set_tests_properties(bench_indexedstring PROPERTIES TIMEOUT 30)
endif()
ecm_add_test(test_itemrepository.cpp
LINK_LIBRARIES Qt5::Test KDev::Serialization KDev::Tests
......
/*
* This file is part of KDevelop
* Copyright 2012-2013 Milian Wolff <mail@milianw.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bench_indexedstring.h"
#include <language/util/kdevhash.h>
#include <serialization/itemrepositoryregistry.h>
#include <serialization/indexedstring.h>
#include <QTest>
#include <QStandardPaths>
QTEST_GUILESS_MAIN(BenchIndexedString)
using namespace KDevelop;
void BenchIndexedString::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
ItemRepositoryRegistry::initialize(m_repositoryPath);
}
void BenchIndexedString::cleanupTestCase()
{
ItemRepositoryRegistry::deleteRepositoryFromDisk(m_repositoryPath);
}
static QVector<QString> generateData()
{
QVector<QString> data;
static const int NUM_ITEMS = 100000;
data.resize(NUM_ITEMS);
for (int i = 0; i < NUM_ITEMS; ++i) {
data[i] = QStringLiteral("/foo/%1").arg(i);
}
return data;
}
void BenchIndexedString::bench_index()
{
const QVector<QString> data = generateData();
QBENCHMARK {
for (const QString& item : data) {
IndexedString idx(item);
Q_UNUSED(idx);
}
}
}
static QVector<uint> setupTest()
{
const QVector<QString> data = generateData();
QVector<uint> indices;
indices.reserve(data.size());
for (const QString& item : data) {
IndexedString idx(item);
indices << idx.index();
}
return indices;
}
void BenchIndexedString::bench_length()
{
const QVector<uint> indices = setupTest();
QBENCHMARK {
for (uint index : indices) {
IndexedString str = IndexedString::fromIndex(index);
str.length();
}
}
}
void BenchIndexedString::bench_qstring()
{
const QVector<uint> indices = setupTest();
QBENCHMARK {
for (uint index : indices) {
IndexedString str = IndexedString::fromIndex(index);
str.str();
}
}
}
void BenchIndexedString::bench_kurl()
{
const QVector<uint> indices = setupTest();
QBENCHMARK {
for (uint index : indices) {
IndexedString str = IndexedString::fromIndex(index);
str.toUrl();
}
}
}
void BenchIndexedString::bench_qhashQString()
{
const QVector<QString> data = generateData();
quint64 sum = 0;
QBENCHMARK {
for (const auto& string : data) {
sum += qHash(string);
}
}
QVERIFY(sum > 0);
}
void BenchIndexedString::bench_qhashIndexedString()
{
const QVector<uint> indices = setupTest();
quint64 sum = 0;
QBENCHMARK {
for (uint index : indices) {
sum += qHash(IndexedString::fromIndex(index));
}
}
QVERIFY(sum > 0);
}
void BenchIndexedString::bench_hashString()
{
const QVector<QString> strings = generateData();
QVector<QByteArray> byteArrays;
byteArrays.reserve(strings.size());
for (const auto& string : strings) {
byteArrays << string.toUtf8();
}
quint64 sum = 0;
QBENCHMARK {
for (const auto& array : qAsConst(byteArrays)) {
sum += IndexedString::hashString(array.constData(), array.length());
}
}
QVERIFY(sum > 0);
}
void BenchIndexedString::bench_kdevhash()
{
const QVector<QString> strings = generateData();
QVector<QByteArray> byteArrays;
byteArrays.reserve(strings.size());
for (const auto& string : strings) {
byteArrays << string.toUtf8();
}
quint64 sum = 0;
QBENCHMARK {
for (const auto& array : qAsConst(byteArrays)) {
sum += KDevHash() << array;
}
}
QVERIFY(sum > 0);
}
void BenchIndexedString::bench_qSet()
{
const QVector<uint> indices = setupTest();
QSet<IndexedString> set;
QBENCHMARK {
for (uint index : indices) {
set.insert(IndexedString::fromIndex(index));
}
}
}
/*
* This file is part of KDevelop
* Copyright 2012-2013 Milian Wolff <mail@milianw.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BENCH_INDEXEDSTRING_H
#define BENCH_INDEXEDSTRING_H
#include <QDir>
#include <QObject>
class BenchIndexedString
: public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void bench_index();
void bench_length();
void bench_qstring();
void bench_kurl();
void bench_qhashQString();
void bench_qhashIndexedString();
void bench_hashString();
void bench_kdevhash();
void bench_qSet();
private:
const QString m_repositoryPath = QDir::tempPath() + QStringLiteral("/bench_indexedstring");
};
#endif // BENCH_INDEXEDSTRING_H
......@@ -21,7 +21,6 @@
#include "test_indexedstring.h"
#include <language/util/kdevhash.h>
#include <serialization/itemrepositoryregistry.h>
#include <serialization/indexedstring.h>
#include <QTest>
......@@ -70,146 +69,6 @@ void TestIndexedString::testUrl()
QTEST(indexed.str(), "string");
}
static QVector<QString> generateData()
{
QVector<QString> data;
static const int NUM_ITEMS = 100000;
data.resize(NUM_ITEMS);
for (int i = 0; i < NUM_ITEMS; ++i) {
data[i] = QStringLiteral("/foo/%1").arg(i);
}
return data;
}
void TestIndexedString::bench_index()
{
const QVector<QString> data = generateData();
QBENCHMARK {
for (const QString& item : data) {
IndexedString idx(item);
Q_UNUSED(idx);
}
}
}
static QVector<uint> setupTest()
{
const QVector<QString> data = generateData();
QVector<uint> indices;
indices.reserve(data.size());
for (const QString& item : data) {
IndexedString idx(item);
indices << idx.index();
}
return indices;
}
void TestIndexedString::bench_length()
{
const QVector<uint> indices = setupTest();
QBENCHMARK {
for (uint index : indices) {
IndexedString str = IndexedString::fromIndex(index);
str.length();
}
}
}
void TestIndexedString::bench_qstring()
{
const QVector<uint> indices = setupTest();
QBENCHMARK {
for (uint index : indices) {
IndexedString str = IndexedString::fromIndex(index);
str.str();
}
}
}
void TestIndexedString::bench_kurl()
{
const QVector<uint> indices = setupTest();
QBENCHMARK {
for (uint index : indices) {
IndexedString str = IndexedString::fromIndex(index);
str.toUrl();
}
}
}
void TestIndexedString::bench_qhashQString()
{
const QVector<QString> data = generateData();
quint64 sum = 0;
QBENCHMARK {
for (const auto& string : data) {
sum += qHash(string);
}
}
QVERIFY(sum > 0);
}
void TestIndexedString::bench_qhashIndexedString()
{
const QVector<uint> indices = setupTest();
quint64 sum = 0;
QBENCHMARK {
for (uint index : indices) {
sum += qHash(IndexedString::fromIndex(index));
}
}
QVERIFY(sum > 0);
}
void TestIndexedString::bench_hashString()
{
const QVector<QString> strings = generateData();
QVector<QByteArray> byteArrays;
byteArrays.reserve(strings.size());
for (const auto& string : strings) {
byteArrays << string.toUtf8();
}
quint64 sum = 0;
QBENCHMARK {
for (const auto& array : qAsConst(byteArrays)) {
sum += IndexedString::hashString(array.constData(), array.length());
}
}
QVERIFY(sum > 0);
}
void TestIndexedString::bench_kdevhash()
{
const QVector<QString> strings = generateData();
QVector<QByteArray> byteArrays;
byteArrays.reserve(strings.size());
for (const auto& string : strings) {
byteArrays << string.toUtf8();
}
quint64 sum = 0;
QBENCHMARK {
for (const auto& array : qAsConst(byteArrays)) {
sum += KDevHash() << array;
}
}
QVERIFY(sum > 0);
}
void TestIndexedString::bench_qSet()
{
const QVector<uint> indices = setupTest();
QSet<IndexedString> set;
QBENCHMARK {
for (uint index : indices) {
set.insert(IndexedString::fromIndex(index));
}
}
}
void TestIndexedString::test()
{
QFETCH(QString, data);
......
......@@ -37,16 +37,6 @@ private Q_SLOTS:
void testUrl_data();
void testUrl();
void bench_index();
void bench_length();
void bench_qstring();
void bench_kurl();
void bench_qhashQString();
void bench_qhashIndexedString();
void bench_hashString();
void bench_kdevhash();
void bench_qSet();
void test();
void test_data();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment