kis_datamanager_benchmark.cpp 6.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 *  Copyright (c) 2007 Boudewijn Rempt boud@valdyas.org
 *
 *  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) any later version.
 *
 *  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, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "kis_datamanager_benchmark.h"
20
#include "kis_benchmark_values.h"
21

22
#include <QTest>
23 24
#include <kis_datamanager.h>

25 26 27 28
// RGBA
#define PIXEL_SIZE 4
//#define CYCLES 100

29 30 31
void KisDatamanagerBenchmark::initTestCase()
{
    // To make sure all the first-time startup costs are done
32 33 34
    quint8 * p = new quint8[PIXEL_SIZE];
    memset(p, 0, PIXEL_SIZE);
    KisDataManager dm(PIXEL_SIZE, p);
35 36 37 38 39 40 41
}

void KisDatamanagerBenchmark::benchmarkCreation()
{
    // tests the cost of creating a new datamanager

    QBENCHMARK {
42 43 44
        quint8 * p = new quint8[PIXEL_SIZE];
        memset(p, 255, PIXEL_SIZE);
        KisDataManager dm(PIXEL_SIZE, p);
45 46 47
    }
}

48 49
void KisDatamanagerBenchmark::benchmarkWriteBytes()
{
50 51 52
    quint8 *p = new quint8[PIXEL_SIZE];
    memset(p, 0, PIXEL_SIZE);
    KisDataManager dm(PIXEL_SIZE, p);
53

54 55
    quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT];
    memset(bytes, 128, PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT);
56 57

    QBENCHMARK {
58 59 60 61
#ifdef CYCLES
        for (int i = 0; i < CYCLES; i++){
            dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
        }
62
#else
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
63
        dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
64
#endif
65
    }
66 67 68 69 70 71

    delete[] bytes;
}

void KisDatamanagerBenchmark::benchmarkReadBytes()
{
72 73 74
    quint8 *p = new quint8[PIXEL_SIZE];
    memset(p, 0, PIXEL_SIZE);
    KisDataManager dm(PIXEL_SIZE, p);
75

76 77
    quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT];
    memset(bytes, 128, PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT);
78 79

    QBENCHMARK {
Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
80
        dm.readBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
81 82 83 84 85 86 87 88
    }

    delete[] bytes;
}


void KisDatamanagerBenchmark::benchmarkReadWriteBytes()
{
89 90 91
    quint8 *p = new quint8[PIXEL_SIZE];
    memset(p, 0, PIXEL_SIZE);
    KisDataManager dm(PIXEL_SIZE, p);
92

93 94
    quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT];
    memset(bytes, 120, PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT);
95

Lukáš Tvrdý's avatar
Lukáš Tvrdý committed
96
    dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
97 98

    QBENCHMARK {
99 100 101 102 103 104 105
#ifdef CYCLES
        for (int i = 0; i < 100; i++){
            dm.readBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
        }
#else
            dm.readBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);    
#endif
106 107
    }
    delete[] bytes;
108 109
}

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
void KisDatamanagerBenchmark::benchmarkReadWriteBytes2()
{
    quint8 *p = new quint8[PIXEL_SIZE];
    memset(p, 0, PIXEL_SIZE);
    KisDataManager dm(PIXEL_SIZE, p);
    
    KisDataManager dab(PIXEL_SIZE, p);

    {
        quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT];
        memset(bytes, 120, PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT);

        dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
        dab.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
        delete[] bytes;
    }

    QBENCHMARK {
        int size = TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT;
        quint8 *bytes = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT];
        quint8 *bytes2 = new quint8[PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT];
        dm.readBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
        dab.readBytes(bytes2, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
        quint8 *bytes_it = bytes;
        quint8 *bytes2_it = bytes2;
        for (int i = 0; i < size; i += PIXEL_SIZE, bytes_it += PIXEL_SIZE, bytes2_it += PIXEL_SIZE)
        {
            memcpy(bytes_it, bytes2_it, PIXEL_SIZE);
        }
        dm.writeBytes(bytes, 0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);
        delete[] bytes;
        delete[] bytes2;
    }
}

Boudewijn Rempt's avatar
Boudewijn Rempt committed
145 146
void KisDatamanagerBenchmark::benchmarkExtent()
{
147 148 149
    quint8 *p = new quint8[PIXEL_SIZE];
    memset(p, 0, PIXEL_SIZE);
    KisDataManager dm(PIXEL_SIZE, p);
150
    quint8 *bytes = new quint8[PIXEL_SIZE * NO_TILE_EXACT_BOUNDARY_WIDTH * NO_TILE_EXACT_BOUNDARY_HEIGHT];
151
    memset(bytes, 0, PIXEL_SIZE * NO_TILE_EXACT_BOUNDARY_WIDTH * NO_TILE_EXACT_BOUNDARY_HEIGHT);
152
    dm.writeBytes(bytes, 0, 0, NO_TILE_EXACT_BOUNDARY_WIDTH, NO_TILE_EXACT_BOUNDARY_HEIGHT);
Boudewijn Rempt's avatar
Boudewijn Rempt committed
153 154
    QBENCHMARK {
        QRect extent = dm.extent();
155
	Q_UNUSED(extent);
Boudewijn Rempt's avatar
Boudewijn Rempt committed
156 157
    }
}
158

Boudewijn Rempt's avatar
Boudewijn Rempt committed
159 160
void KisDatamanagerBenchmark::benchmarkClear()
{
161 162 163 164
    quint8 *p = new quint8[PIXEL_SIZE];
    memset(p, 128, PIXEL_SIZE);
    KisDataManager dm(PIXEL_SIZE, p);
    quint8 *bytes = new quint8[PIXEL_SIZE * NO_TILE_EXACT_BOUNDARY_WIDTH * NO_TILE_EXACT_BOUNDARY_HEIGHT];
165
    
166
    memset(bytes, 0, PIXEL_SIZE * NO_TILE_EXACT_BOUNDARY_WIDTH * NO_TILE_EXACT_BOUNDARY_HEIGHT);
167 168 169 170 171 172
    dm.writeBytes(bytes, 0, 0, NO_TILE_EXACT_BOUNDARY_WIDTH, NO_TILE_EXACT_BOUNDARY_HEIGHT);

    // 80% of the image will be cleared
    quint32 clearWidth = 0.8 * NO_TILE_EXACT_BOUNDARY_WIDTH;
    quint32 clearHeight = 0.8 * NO_TILE_EXACT_BOUNDARY_HEIGHT;

Boudewijn Rempt's avatar
Boudewijn Rempt committed
173
    QBENCHMARK {
174
        dm.clear(0, 0, clearWidth, clearHeight, p);
Boudewijn Rempt's avatar
Boudewijn Rempt committed
175 176 177 178
    }

}

179 180 181 182 183 184 185 186 187 188 189 190 191

void KisDatamanagerBenchmark::benchmarkMemCpy()
{
    quint64 imgSize = PIXEL_SIZE * TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT;
    quint8 * src = new quint8[imgSize];
    quint8 * dst = new quint8[imgSize];
    memset(src,128, imgSize);
    memset(dst,0, imgSize);
    QBENCHMARK{
#ifdef CYCLES
        for (int i = 0; i < 100; i++){
            memcpy(dst, src , imgSize);
        }
192
#else
193 194 195
            memcpy(dst, src , imgSize);
#endif
    }
Boudewijn Rempt's avatar
Boudewijn Rempt committed
196 197 198

    delete[] src;
    delete[] dst;
199 200 201
}


202
QTEST_MAIN(KisDatamanagerBenchmark)