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

« back to all changes in this revision

Viewing changes to libs/pigment/benchmarks/KoColorSpacesBenchmark.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2010 Cyrille Berger <cberger@cberger.net>
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU Lesser 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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
#include "KoColorSpacesBenchmark.h"
 
20
 
 
21
#include <qtest_kde.h>
 
22
#include <KoColorSpaceRegistry.h>
 
23
#include <KoColorSpace.h>
 
24
 
 
25
#define NB_PIXELS 1000000
 
26
 
 
27
void KoColorSpacesBenchmark::createRowsColumns()
 
28
{
 
29
    QTest::addColumn<QString>("modelID");
 
30
    QTest::addColumn<QString>("depthID");
 
31
    QList<const KoColorSpace*> colorSpaces = KoColorSpaceRegistry::instance()->allColorSpaces(KoColorSpaceRegistry::AllColorSpaces, KoColorSpaceRegistry::OnlyDefaultProfile);
 
32
    foreach(const KoColorSpace* colorSpace, colorSpaces) {
 
33
        QTest::newRow(colorSpace->name().toLatin1().data()) << colorSpace->colorModelId().id() << colorSpace->colorDepthId().id();
 
34
    }
 
35
}
 
36
 
 
37
#define START_BENCHMARK \
 
38
    QFETCH(QString, modelID); \
 
39
    QFETCH(QString, depthID); \
 
40
    \
 
41
    const KoColorSpace* colorSpace = KoColorSpaceRegistry::instance()->colorSpace(modelID, depthID, 0); \
 
42
    int pixelSize = colorSpace->pixelSize(); \
 
43
    quint8* data = new quint8[NB_PIXELS * pixelSize]; \
 
44
    memset(data, 0, NB_PIXELS * pixelSize);
 
45
 
 
46
#define END_BENCHMARK \
 
47
    delete[] data;
 
48
 
 
49
void KoColorSpacesBenchmark::benchmarkAlpha_data()
 
50
{
 
51
    createRowsColumns();
 
52
}
 
53
 
 
54
void KoColorSpacesBenchmark::benchmarkAlpha()
 
55
{
 
56
    START_BENCHMARK
 
57
    QBENCHMARK {
 
58
        quint8* data_it = data;
 
59
        for (int i = 0; i < NB_PIXELS; ++i) {
 
60
            colorSpace->opacityU8(data_it);
 
61
            data_it += pixelSize;
 
62
        }
 
63
    }
 
64
    END_BENCHMARK
 
65
}
 
66
 
 
67
void KoColorSpacesBenchmark::benchmarkAlpha2_data()
 
68
{
 
69
    createRowsColumns();
 
70
}
 
71
 
 
72
void KoColorSpacesBenchmark::benchmarkAlpha2()
 
73
{
 
74
    START_BENCHMARK
 
75
    QBENCHMARK {
 
76
        quint8* data_it = data;
 
77
        for (int i = 0; i < NB_PIXELS; ++i) {
 
78
            colorSpace->opacityF(data_it);
 
79
            data_it += pixelSize;
 
80
        }
 
81
    }
 
82
    END_BENCHMARK
 
83
}
 
84
 
 
85
void KoColorSpacesBenchmark::benchmarkSetAlpha_data()
 
86
{
 
87
    createRowsColumns();
 
88
}
 
89
 
 
90
void KoColorSpacesBenchmark::benchmarkSetAlpha()
 
91
{
 
92
    START_BENCHMARK
 
93
    QBENCHMARK {
 
94
        colorSpace->setOpacity(data, OPACITY_OPAQUE_U8, NB_PIXELS);
 
95
    }
 
96
    END_BENCHMARK
 
97
}
 
98
 
 
99
void KoColorSpacesBenchmark::benchmarkSetAlpha2_data()
 
100
{
 
101
    createRowsColumns();
 
102
}
 
103
 
 
104
void KoColorSpacesBenchmark::benchmarkSetAlpha2()
 
105
{
 
106
    START_BENCHMARK
 
107
    QBENCHMARK {
 
108
        colorSpace->setOpacity(data, OPACITY_OPAQUE_F, NB_PIXELS);
 
109
    }
 
110
    END_BENCHMARK
 
111
}
 
112
 
 
113
void KoColorSpacesBenchmark::benchmarkSetAlphaIndividualCall_data()
 
114
{
 
115
    createRowsColumns();
 
116
}
 
117
 
 
118
void KoColorSpacesBenchmark::benchmarkSetAlphaIndividualCall()
 
119
{
 
120
    START_BENCHMARK
 
121
    QBENCHMARK {
 
122
        quint8* data_it = data;
 
123
        for (int i = 0; i < NB_PIXELS; ++i) {
 
124
            colorSpace->setOpacity(data_it, OPACITY_OPAQUE_U8, 1);
 
125
            data_it += pixelSize;
 
126
        }
 
127
    }
 
128
    END_BENCHMARK
 
129
}
 
130
 
 
131
void KoColorSpacesBenchmark::benchmarkSetAlpha2IndividualCall_data()
 
132
{
 
133
    createRowsColumns();
 
134
}
 
135
 
 
136
void KoColorSpacesBenchmark::benchmarkSetAlpha2IndividualCall()
 
137
{
 
138
    START_BENCHMARK
 
139
    QBENCHMARK {
 
140
        quint8* data_it = data;
 
141
        for (int i = 0; i < NB_PIXELS; ++i) {
 
142
            colorSpace->setOpacity(data_it, OPACITY_OPAQUE_F, 1);
 
143
            data_it += pixelSize;
 
144
        }
 
145
    }
 
146
    END_BENCHMARK
 
147
}
 
148
 
 
149
QTEST_KDEMAIN(KoColorSpacesBenchmark, GUI)
 
150
 
 
151
#include "KoColorSpacesBenchmark.moc"