2
* Copyright (c) 2010 Dmitry Kazakov <dimula73@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "kis_memory_pool_test.h"
20
#include <qtest_kde.h>
22
#include "kis_debug.h"
24
#include "tiles3/kis_memory_pool.h"
26
#define OBJECT_SIZE 16384 //bytes (size of a usual tile data)
29
#define NUM_CYCLES 100000
30
#define NUM_OBJECTS 64 // for tiles - 64 == area of 512x512px
35
quint8 m_data[OBJECT_SIZE];
38
typedef KisMemoryPool<TestingClass, POOL_SIZE> TestingMemoryPool;
41
class KisPoolStressJob : public QRunnable
44
KisPoolStressJob(TestingMemoryPool &pool)
50
qsrand(QTime::currentTime().msec());
51
for(qint32 i = 0; i < NUM_CYCLES; i++) {
56
for(qint32 j = 0; j < NUM_OBJECTS; j++) {
57
m_pointer[j] = m_pool.pop();
58
Q_ASSERT(m_pointer[j]);
59
// check for sigsegv ;)
60
((quint8*)m_pointer[j])[0] = i;
64
for(qint32 j = 0; j < NUM_OBJECTS; j++) {
65
// are we the only writers here?
66
Q_ASSERT(((quint8*)m_pointer[j])[0] == (i-1) % 256);
67
m_pool.push(m_pointer[j]);
75
void* m_pointer[NUM_OBJECTS];
76
TestingMemoryPool &m_pool;
79
void KisMemoryPoolTest::benchmarkMemoryPool()
81
TestingMemoryPool memoryPool;
84
pool.setMaxThreadCount(NUM_THREADS);
87
for(qint32 i = 0; i < NUM_THREADS; i++) {
88
KisPoolStressJob *job = new KisPoolStressJob(memoryPool);
97
class KisAllocStressJob : public QRunnable
105
qsrand(QTime::currentTime().msec());
106
for(qint32 i = 0; i < NUM_CYCLES; i++) {
111
for(qint32 j = 0; j < NUM_OBJECTS; j++) {
112
m_pointer[j] = new TestingClass;
113
Q_ASSERT(m_pointer[j]);
114
// check for sigsegv ;)
115
((quint8*)m_pointer[j])[0] = i;
119
for(qint32 j = 0; j < NUM_OBJECTS; j++) {
120
// are we the only writers here?
121
Q_ASSERT(((quint8*)m_pointer[j])[0] == (i-1) % 256);
122
delete (TestingClass*)m_pointer[j];
130
void* m_pointer[NUM_OBJECTS];
133
void KisMemoryPoolTest::benchmarkAlloc()
136
pool.setMaxThreadCount(NUM_THREADS);
139
for(qint32 i = 0; i < NUM_THREADS; i++) {
140
KisAllocStressJob *job = new KisAllocStressJob();
149
QTEST_KDEMAIN(KisMemoryPoolTest, NoGUI)
150
#include "kis_memory_pool_test.moc"