~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/image/tiles3/tests/dm_perfomance_test/dm_pf_test.cc

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <iostream>
2
 
 
3
 
#include <valgrind/callgrind.h>
4
 
 
5
 
#include "kis_tile.h"
6
 
#include "kis_tile_data_store.h"
7
 
#include "kis_tile_data.h"
8
 
#include "kis_tiled_data_manager.h"
9
 
 
10
 
#define PIXEL_SIZE 6
11
 
quint8   pixel[PIXEL_SIZE];
12
 
 
13
 
#define NUM_CYCLES 2
14
 
#define NUM_CYCLES_SMALL 2
15
 
 
16
 
 
17
 
void testPlanarRW(KisTiledDataManager &dm);
18
 
void testRW(KisTiledDataManager &dm);
19
 
 
20
 
using namespace std;
21
 
 
22
 
#include <sys/time.h>
23
 
#include <sys/times.h>
24
 
 
25
 
#define prop(fst, snd) ((fst-snd)/snd*100.)
26
 
 
27
 
#define startMeasure(msg, tv, tms)               \
28
 
    do {                                         \
29
 
        printf("%s:\t", msg);                    \
30
 
        gettimeofday(&tv, NULL);                 \
31
 
        times(&tms);                             \
32
 
    } while(0)
33
 
 
34
 
#define endMeasure(tv, tms, rtime, utime, cutime)                    \
35
 
    do {                                                             \
36
 
        struct timeval new_tv;                                       \
37
 
        struct tms     new_tms;                                      \
38
 
        gettimeofday(&new_tv, NULL);                                 \
39
 
        times(&new_tms);                                             \
40
 
        double rsec = double(new_tv.tv_sec - tv.tv_sec) +            \
41
 
                      double(new_tv.tv_usec - tv.tv_usec)/1000000;             \
42
 
        double usec = (double)(new_tms.tms_utime - tms.tms_utime)    \
43
 
                      / sysconf(_SC_CLK_TCK);                                  \
44
 
        double cusec = (double)(new_tms.tms_cutime - tms.tms_cutime) \
45
 
                       / sysconf(_SC_CLK_TCK);                                  \
46
 
        rtime+=rsec;                                                 \
47
 
        utime+=usec;                                                 \
48
 
        cutime+=cusec;                                               \
49
 
        printf("\treal: %5.3f\tuser: %5.3f\tcuser: %5.3f\n",         \
50
 
               rsec, usec, cusec);                                   \
51
 
    } while(0)
52
 
#define meanValues(num, rstime, ustime, custime)                  \
53
 
    do {                                                          \
54
 
        rstime/=num;                                              \
55
 
        ustime/=num;                                              \
56
 
        custime/=num;                                             \
57
 
        printf("---\n");                                          \
58
 
        printf("Mean value:\t\t\treal: %5.3f\tuser: %5.3f"        \
59
 
               "\tcuser: %5.3f\n",                                \
60
 
               double(rstime), double(ustime), double(custime));  \
61
 
    } while(0)
62
 
 
63
 
#define zeroValues(rstime, ustime, custime) (rstime=ustime=custime=0)
64
 
 
65
 
int main()
66
 
{
67
 
    memset(pixel, 8, PIXEL_SIZE);
68
 
    KisTiledDataManager dm(PIXEL_SIZE, pixel);
69
 
 
70
 
    testRW(dm);
71
 
    testPlanarRW(dm);
72
 
 
73
 
    return 0;
74
 
}
75
 
 
76
 
void testRW(KisTiledDataManager &dm)
77
 
{
78
 
    struct timeval tv;
79
 
    struct tms     tms;
80
 
    double rstime = 0;
81
 
    double ustime = 0;
82
 
    double custime = 0;
83
 
 
84
 
    QRect dataRect;
85
 
    dataRect.setCoords(60, 60, 7110, 7110);
86
 
 
87
 
    const qint32 dataSize = dataRect.width() * dataRect.height() * PIXEL_SIZE;
88
 
 
89
 
    quint8 *data = new quint8[dataSize];
90
 
    for (qint32 i = 0; i < dataRect.height(); i++) {
91
 
        memset(data, i % 256, dataRect.width()*PIXEL_SIZE);
92
 
    }
93
 
 
94
 
 
95
 
 
96
 
 
97
 
    /*BLOCK1**************************************************/
98
 
    printf("-----------------------------------\n");
99
 
    printf("One loop to warm up COW\n");
100
 
    for (int i = 0; i < NUM_CYCLES_SMALL; i++) {
101
 
        printf("\tcycle %d", i);
102
 
        startMeasure("", tv, tms);
103
 
 
104
 
        dm.writeBytes(data, dataRect.left(), dataRect.top(),
105
 
                      dataRect.width(), dataRect.height());
106
 
 
107
 
        endMeasure(tv, tms, rstime, ustime, custime);
108
 
    }
109
 
    meanValues(NUM_CYCLES_SMALL, rstime, ustime, custime);
110
 
 
111
 
 
112
 
    /*BLOCK2**************************************************/
113
 
    /*    printf("-----------------------------------\n");
114
 
    printf("Test writing with heavy COW'ing\n");
115
 
    zeroValues(rstime, ustime, custime);
116
 
    for(int i=0; i<NUM_CYCLES_SMALL; i++) {
117
 
        printf("\tcycle %d", i);
118
 
        startMeasure("", tv, tms);
119
 
 
120
 
        {
121
 
            KisTiledDataManager dm1(PIXEL_SIZE, pixel);
122
 
            dm1.writeBytes(data, dataRect.left(), dataRect.top(),
123
 
                           dataRect.width(), dataRect.height());
124
 
        }
125
 
 
126
 
        endMeasure(tv,tms, rstime, ustime, custime);
127
 
    }
128
 
    meanValues(NUM_CYCLES_SMALL, rstime, ustime, custime);
129
 
    */
130
 
 
131
 
    /*BLOCK3**************************************************/
132
 
    printf("-----------------------------------\n");
133
 
    printf("Now COW is done. Test actual writing\n");
134
 
    printf("KisTileProcessor subsystem (threading is OFF)\n");
135
 
    zeroValues(rstime, ustime, custime);
136
 
    for (int i = 0; i < NUM_CYCLES; i++) {
137
 
        printf("\tcycle %d", i);
138
 
        startMeasure("", tv, tms);
139
 
 
140
 
        dm.writeBytes(data, dataRect.left(), dataRect.top(),
141
 
                      dataRect.width(), dataRect.height());
142
 
 
143
 
        endMeasure(tv, tms, rstime, ustime, custime);
144
 
    }
145
 
    meanValues(NUM_CYCLES, rstime, ustime, custime);
146
 
 
147
 
    quint8 *read_data = new quint8[dataSize];
148
 
    memset(read_data, 255, dataSize);
149
 
 
150
 
    /*BLOCK4**************************************************/
151
 
    printf("-----------------------------------\n");
152
 
    printf("Read and consistency test\n");
153
 
    zeroValues(rstime, ustime, custime);
154
 
    for (int i = 0; i < NUM_CYCLES; i++) {
155
 
        printf("\tcycle %d", i);
156
 
        startMeasure("", tv, tms);
157
 
 
158
 
        dm.readBytes(read_data, dataRect.left(), dataRect.top(),
159
 
                     dataRect.width(), dataRect.height());
160
 
 
161
 
        endMeasure(tv, tms, rstime, ustime, custime);
162
 
    }
163
 
    meanValues(NUM_CYCLES, rstime, ustime, custime);
164
 
 
165
 
    printf("Consistency: ");
166
 
    int err = memcmp(data, read_data, dataSize);
167
 
    if (!err) {
168
 
        printf("OK\n");
169
 
    } else {
170
 
        printf("FAILED\n");
171
 
        printf("data and read_data are not the same! (%d)\n", err);
172
 
    }
173
 
 
174
 
    delete[] read_data;
175
 
    delete[] data;
176
 
}
177
 
 
178
 
void testPlanarRW(KisTiledDataManager &dm)
179
 
{
180
 
    struct timeval tv;
181
 
    struct tms     tms;
182
 
    double rstime = 0;
183
 
    double ustime = 0;
184
 
    double custime = 0;
185
 
 
186
 
 
187
 
    QRect dataRect;
188
 
    dataRect.setCoords(60, 60, 7110, 7110);
189
 
    const qint32 numPixels = dataRect.width() * dataRect.height();
190
 
 
191
 
    QVector<quint8*> planes;
192
 
    QVector<quint8*> read_planes;
193
 
    QVector<qint32>  channelSizes;
194
 
 
195
 
    for (qint32 i = 0; i < 3; i++) {
196
 
        channelSizes.append(i);
197
 
        quint8 *data = new quint8[i*numPixels];
198
 
        memset(data, i + 10, i*numPixels);
199
 
        planes.append(data);
200
 
    }
201
 
 
202
 
    printf("Strarting test planar write\n");
203
 
    zeroValues(rstime, ustime, custime);
204
 
    for (int i = 0; i < NUM_CYCLES; i++) {
205
 
        printf("\tcycle %d", i);
206
 
        startMeasure("", tv, tms);
207
 
 
208
 
        dm.writePlanarBytes(planes, channelSizes,
209
 
                            dataRect.left(), dataRect.top(),
210
 
                            dataRect.width(), dataRect.height());
211
 
 
212
 
        endMeasure(tv, tms, rstime, ustime, custime);
213
 
    }
214
 
    meanValues(NUM_CYCLES, rstime, ustime, custime);
215
 
 
216
 
 
217
 
 
218
 
    printf("---\nStrarting test planar read\n");
219
 
    zeroValues(rstime, ustime, custime);
220
 
    for (int i = 0; i < NUM_CYCLES; i++) {
221
 
        printf("\tcycle %d", i);
222
 
        startMeasure("", tv, tms);
223
 
 
224
 
        read_planes = dm.readPlanarBytes(channelSizes,
225
 
                                         dataRect.left(), dataRect.top(),
226
 
                                         dataRect.width(), dataRect.height());
227
 
 
228
 
        endMeasure(tv, tms, rstime, ustime, custime);
229
 
    }
230
 
    meanValues(NUM_CYCLES, rstime, ustime, custime);
231
 
 
232
 
    int err;
233
 
    int errSum = 0;
234
 
    for (qint32 i = 0; i < 3; i++) {
235
 
        err = memcmp(planes[i], read_planes[i], i * numPixels);
236
 
        err *= err;
237
 
        errSum += err;
238
 
        delete[] planes[i];
239
 
        delete[] read_planes[i];
240
 
 
241
 
    }
242
 
 
243
 
    printf("Planar consistency: ");
244
 
    if (!errSum) {
245
 
        printf("OK\n");
246
 
    } else {
247
 
        printf("FAILED\n");
248
 
        printf("planar and read_planar are not the same! (%d)\n", errSum);
249
 
    }
250
 
}
251
 
 
252