diff options
author | David Faure <david.faure@kdab.com> | 2016-08-04 10:01:21 +0200 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2016-08-05 09:56:12 +0000 |
commit | 434c52269564c84e3ea57242b7aaa2fd7cad3f54 (patch) | |
tree | fa3818b5b59278d6f37e7bca834b6f908f15b885 /tests | |
parent | eb4bcdd8cec77c558cc75d31730cff89852dd684 (diff) |
Improve performance of QColor::name, now more than 4 times faster
Before: HexRgb: 0.00230 ms per iteration, HexArgb: 0.00290 ms per iteration
After: HexRgb: 0.00051 ms per iteration, HexArgb: 0.00061 ms per iteration
This showed up as a relevant optimization when profiling KIconLoader
which uses QColor::name() as part of the key -- thanks to Mark Gaiser for
the investigation and first suggestion of a solution. I have also seen
customer code writing a replacement for QColor::name() because it was
too slow to be used as a hash key.
Change-Id: I009ccdd712ea0d869d466e2c9894e0cea58f0e68
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/painting/qcolor/tst_qcolor.cpp | 2 | ||||
-rw-r--r-- | tests/benchmarks/gui/painting/painting.pro | 1 | ||||
-rw-r--r-- | tests/benchmarks/gui/painting/qcolor/qcolor.pro | 7 | ||||
-rw-r--r-- | tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp | 67 |
4 files changed, 77 insertions, 0 deletions
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index b81a4e2c4c..289b06fc62 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -284,6 +284,8 @@ void tst_QColor::name_data() QTest::newRow("global color darkMagenta") << QColor(Qt::darkMagenta) << "#800080" << QColor::HexRgb; QTest::newRow("global color darkYellow") << QColor(Qt::darkYellow) << "#808000" << QColor::HexRgb; QTest::newRow("transparent red") << QColor(255, 0, 0, 102) << "#66ff0000" << QColor::HexArgb; + QTest::newRow("fully_transparent_green_rgb") << QColor(0, 0, 255, 0) << "#0000ff" << QColor::HexRgb; + QTest::newRow("fully_transparent_green_argb") << QColor(0, 0, 255, 0) << "#000000ff" << QColor::HexArgb; } void tst_QColor::name() diff --git a/tests/benchmarks/gui/painting/painting.pro b/tests/benchmarks/gui/painting/painting.pro index 0eb7fa92a7..cdcfc9b318 100644 --- a/tests/benchmarks/gui/painting/painting.pro +++ b/tests/benchmarks/gui/painting/painting.pro @@ -1,5 +1,6 @@ TEMPLATE = subdirs SUBDIRS = \ + qcolor \ qpainter \ qregion \ qtransform \ diff --git a/tests/benchmarks/gui/painting/qcolor/qcolor.pro b/tests/benchmarks/gui/painting/qcolor/qcolor.pro new file mode 100644 index 0000000000..5ceb702323 --- /dev/null +++ b/tests/benchmarks/gui/painting/qcolor/qcolor.pro @@ -0,0 +1,7 @@ +QT += testlib +QT += gui-private + +TEMPLATE = app +TARGET = tst_bench_qcolor + +SOURCES += tst_qcolor.cpp diff --git a/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp b/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp new file mode 100644 index 0000000000..b67fa450d7 --- /dev/null +++ b/tests/benchmarks/gui/painting/qcolor/tst_qcolor.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QColor> + + +class tst_QColor : public QObject +{ + Q_OBJECT + +private slots: + void nameRgb(); + void nameArgb(); +}; + +void tst_QColor::nameRgb() +{ + QColor color(128, 255, 10); + QCOMPARE(color.name(), QStringLiteral("#80ff0a")); + QBENCHMARK { + color.name(); + } +} + +void tst_QColor::nameArgb() +{ + QColor color(128, 255, 0, 102); + QCOMPARE(color.name(QColor::HexArgb), QStringLiteral("#6680ff00")); + QBENCHMARK { + color.name(QColor::HexArgb); + } +} + +QTEST_MAIN(tst_QColor) + +#include "tst_qcolor.moc" |