/**************************************************************************** ** ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the Qt3D module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL3$ ** 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 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPLv3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in ** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include #include #include #include #include class tst_QResourceManager : public QObject { Q_OBJECT private Q_SLOTS: void benchmarkAllocateSmallResources(); void benchmarkAccessSmallResources(); void benchmarkLookupSmallResources(); void benchmarRandomAccessSmallResources(); void benchmarkRandomLookupSmallResources(); void benchmarkReleaseSmallResources(); void benchmarkAllocateBigResources(); void benchmarkAccessBigResources(); void benchmarRandomAccessBigResources(); void benchmarkLookupBigResources(); void benchmarkRandomLookupBigResources(); void benchmarkReleaseBigResources(); }; class tst_SmallArrayResource { public: tst_SmallArrayResource() : m_value(0) {} int m_value; }; class tst_BigArrayResource { public: QMatrix4x4 m_matrix; }; template void benchmarkAllocateResources() { Qt3DCore::QResourceManager manager; volatile Resource *c; QBENCHMARK_ONCE { const int max = (1 << 16) - 1; for (int i = 0; i < max; i++) c = manager.getOrCreateResource(i); } Q_UNUSED(c); } template void benchmarkAccessResources() { Qt3DCore::QResourceManager manager; const int max = (1 << 16) - 1; QVector > handles(max); for (int i = 0; i < max; i++) handles[i] = manager.acquire(); volatile Resource *c; QBENCHMARK { for (int i = 0; i < max; i++) c = manager.data(handles[i]); } Q_UNUSED(c); } template void benchmarkRandomAccessResource() { Qt3DCore::QResourceManager manager; const int max = (1 << 16) - 1; QVector > handles(max); for (int i = 0; i < max; i++) handles[i] = manager.acquire(); std::srand(std::time(0)); std::random_shuffle(handles.begin(), handles.end()); volatile Resource *c; QBENCHMARK { for (int i = 0; i < max; i++) c = manager.data(handles[i]); } Q_UNUSED(c); } template void benchmarkLookupResources() { Qt3DCore::QResourceManager manager; const int max = (1 << 16) - 1; for (int i = 0; i < max; i++) manager.getOrCreateResource(i); volatile Resource *c; QBENCHMARK { for (int i = 0; i < max; i++) c = manager.lookupResource(i); } Q_UNUSED(c); } template void benchmarkRandomLookupResources() { Qt3DCore::QResourceManager manager; const int max = (1 << 16) - 1; QVector resourcesIndices(max); for (int i = 0; i < max; i++) { manager.getOrCreateResource(i); resourcesIndices[i] = i; } std::srand(std::time(0)); std::random_shuffle(resourcesIndices.begin(), resourcesIndices.end()); volatile Resource *c; QBENCHMARK { for (int i = 0; i < max; i++) c = manager.lookupResource(resourcesIndices[i]); } Q_UNUSED(c); } template void benchmarkReleaseResources() { Qt3DCore::QResourceManager manager; const int max = (1 << 16) - 1; QVector > handles(max); for (int i = 0; i < max; i++) handles[i] = manager.acquire(); QBENCHMARK_ONCE { manager.reset(); } } void tst_QResourceManager::benchmarkAllocateSmallResources() { benchmarkAllocateResources(); } void tst_QResourceManager::benchmarkAccessSmallResources() { benchmarkAccessResources(); } void tst_QResourceManager::benchmarkLookupSmallResources() { benchmarkLookupResources(); } void tst_QResourceManager::benchmarRandomAccessSmallResources() { benchmarkRandomAccessResource(); } void tst_QResourceManager::benchmarkRandomLookupSmallResources() { benchmarkRandomLookupResources(); } void tst_QResourceManager::benchmarkReleaseSmallResources() { benchmarkReleaseResources(); } void tst_QResourceManager::benchmarkAllocateBigResources() { benchmarkAllocateResources(); } void tst_QResourceManager::benchmarkAccessBigResources() { benchmarkAccessResources(); } void tst_QResourceManager::benchmarRandomAccessBigResources() { benchmarkRandomAccessResource(); } void tst_QResourceManager::benchmarkLookupBigResources() { benchmarkLookupResources(); } void tst_QResourceManager::benchmarkRandomLookupBigResources() { benchmarkRandomLookupResources(); } void tst_QResourceManager::benchmarkReleaseBigResources() { benchmarkReleaseResources(); } QTEST_APPLESS_MAIN(tst_QResourceManager) #include "tst_bench_qresourcesmanager.moc"