Debian Codegraph @

tests/benchmarks/core/qresourcesmanager/arraypolicy/tst_bench_arraypolicy.cpp

raw symbols SCIP
1 // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QtTest/QtTest>
5 #include <QMatrix4x4>
6 #include <Qt3DCore/private/qresourcemanager_p.h>
7
8 class tst_ArrayPolicy : public QObject
9 {
10 Q_OBJECT
11 private Q_SLOTS:
12 void benchmarkDynamicAllocateSmallResources();
13 void benchmarkDynamicReleaseSmallResources();
14 void benchmarkDynamicAllocateBigResources();
15 void benchmarkDynamicReleaseBigResources();
16 };
17
18 struct SmallType
19 {
20 quint32 data;
21 };
22
23 struct BigType
24 {
25 QMatrix4x4 a;
26 };
27
28 template<typename T>
29 void benchmarkAllocateResources()
30 {
31 Qt3DCore::ArrayAllocatingPolicy<T> allocator;
32
33 const int max = (1 << 16) - 1;
34 QBENCHMARK_ONCE {
35 for (int i = 0; i < max; i++) {
36 (void) allocator.allocateResource();
37 }
38 }
39 }
40
41 template<typename T>
42 void benchmarkReleaseResources()
43 {
44 Qt3DCore::ArrayAllocatingPolicy<T> allocator;
45
46 const int max = (1 << 16) - 1;
47 std::vector<Qt3DCore::QHandle<T>> resources(max);
48 for (size_t i = 0; i < max; i++) {
49 resources[i] = allocator.allocateResource();
50 }
51
52 QBENCHMARK_ONCE {
53 for (auto ptr : std::as_const(resources)) {
54 allocator.releaseResource(ptr);
55 }
56 }
57 }
58
59 void tst_ArrayPolicy::benchmarkDynamicAllocateSmallResources()
60 {
61 benchmarkAllocateResources<SmallType>();
62 }
63
64 void tst_ArrayPolicy::benchmarkDynamicReleaseSmallResources()
65 {
66 benchmarkReleaseResources<SmallType>();
67 }
68
69 void tst_ArrayPolicy::benchmarkDynamicAllocateBigResources()
70 {
71 benchmarkAllocateResources<BigType>();
72 }
73
74 void tst_ArrayPolicy::benchmarkDynamicReleaseBigResources()
75 {
76 benchmarkReleaseResources<BigType>();
77 }
78
79 QTEST_APPLESS_MAIN(tst_ArrayPolicy)
80
81 #include "tst_bench_arraypolicy.moc"