35 #undef QT_USE_FAST_OPERATOR_PLUS
36 #undef QT_USE_FAST_CONCATENATION
37 #define QT_NO_CAST_FROM_ASCII
38 #define QT_NO_CAST_TO_ASCII
46 #define QT_USE_FAST_OPERATOR_PLUS
47 #define QT_USE_FAST_CONCATENATION
48 #define QT_NO_CAST_FROM_ASCII
49 #define QT_NO_CAST_TO_ASCII
55 #undef QT_USE_FAST_OPERATOR_PLUS
56 #undef QT_USE_FAST_CONCATENATION
57 #undef QT_NO_CAST_FROM_ASCII
58 #undef QT_NO_CAST_TO_ASCII
65 #define QT_USE_FAST_OPERATOR_PLUS
66 #define QT_USE_FAST_CONCATENATION
67 #undef QT_NO_CAST_FROM_ASCII
68 #undef QT_NO_CAST_TO_ASCII
92 #define COMPARE(a, b) QCOMPARE(a, b)
95 #define SEP(s) qDebug() << "\n\n-------- " s " ---------";
97 #define LITERAL "some string literal"
124 for (
int i = 0;
i <
N; ++
i) {
126 s +=
QString(l1string + l1string).size();
127 s +=
QString(l1string + l1string + l1string).size();
128 s +=
QString(l1string + l1string + l1string + l1string).size();
129 s +=
QString(l1string + l1string + l1string + l1string + l1string).size();
131 s +=
QString(achar + l1string + achar).size();
139 for (
int i = 0;
i <
N; ++
i) {
141 s +=
QString(l1literal
P l1literal).size();
142 s +=
QString(l1literal
P l1literal
P l1literal).size();
143 s +=
QString(l1literal
P l1literal
P l1literal
P l1literal).size();
144 s +=
QString(l1literal
P l1literal
P l1literal
P l1literal
P l1literal).size();
146 s +=
QString(achar % l1literal % achar).size();
154 qDebug() <<
"\nIn each block the QStringBuilder based result appear first "
155 "(with a 'b_' prefix), QStringBased second ('q_' prefix), std::string "
156 "last ('s_' prefix)\n";
159 void separator_1() {
SEP(
"literal + literal (builder first)"); }
161 void b_2_l1literal() {
165 #ifndef QT_NO_CAST_FROM_ASCII
166 void b_l1literal_LITERAL() {
171 void q_2_l1string() {
177 void separator_2() {
SEP(
"2 strings"); }
189 COMPARE(stdr, stdstring + stdstring);
193 void separator_2b() {
SEP(
"3 strings"); }
204 QBENCHMARK { stdr = stdstring + stdstring + stdstring; }
205 COMPARE(stdr, stdstring + stdstring + stdstring);
208 void separator_2e() {
SEP(
"4 strings"); }
219 QBENCHMARK { stdr = stdstring + stdstring + stdstring + stdstring; }
220 COMPARE(stdr, stdstring + stdstring + stdstring + stdstring);
225 void separator_2a() {
SEP(
"string + literal (builder first)"); }
227 void b_string_l1literal() {
231 #ifndef QT_NO_CAST_FROM_ASCII
232 void b_string_LITERAL() {
236 void b_LITERAL_string() {
241 void b_string_l1string() {
245 void q_string_l1literal() {
249 void q_string_l1string() {
253 void s_LITERAL_string() {
255 COMPARE(stdr, stdstring + stdstring);
259 void separator_3() {
SEP(
"3 literals"); }
261 void b_3_l1literal() {
265 void q_3_l1string() {
269 void s_3_l1string() {
271 COMPARE(stdr, stdstring + stdstring + stdstring);
275 void separator_4() {
SEP(
"4 literals"); }
277 void b_4_l1literal() {
281 void q_4_l1string() {
282 QBENCHMARK {
r = l1string + l1string + l1string + l1string; }
287 void separator_5() {
SEP(
"5 literals"); }
289 void b_5_l1literal() {
290 QBENCHMARK {
r = l1literal
P l1literal
P l1literal
P l1literal
P l1literal; }
294 void q_5_l1string() {
295 QBENCHMARK {
r = l1string + l1string + l1string + l1string + l1string; }
300 void separator_6() {
SEP(
"4 chars"); }
302 void b_string_4_char() {
303 QBENCHMARK {
r =
string + achar + achar + achar + achar; }
307 void q_string_4_char() {
308 QBENCHMARK {
r =
string + achar + achar + achar + achar; }
312 void s_string_4_char() {
313 QBENCHMARK { stdr = stdstring +
'c' +
'c' +
'c' +
'c'; }
314 COMPARE(stdr, stdstring +
'c' +
'c' +
'c' +
'c');
318 void separator_7() {
SEP(
"char + string + char"); }
320 void b_char_string_char() {
325 void q_char_string_char() {
330 void s_char_string_char() {
332 COMPARE(stdr,
'c' + stdstring +
'c');
336 void separator_8() {
SEP(
"string.arg"); }
338 void b_string_arg() {
344 void q_string_arg() {
350 void q_bytearray_arg() {
356 void separator_9() {
SEP(
"QString::reserve()"); }
365 void b_reserve_lit() {
383 void s_reserve_lit() {
415 #include "tst_bench_qstringbuilder.moc"
small capitals from c petite p scientific i
[1]
The QByteArray class provides an array of bytes.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
The QObject class is the base class of all Qt objects.
The QString class provides a Unicode character string.
static QString fromLatin1(QByteArrayView ba)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei const GLchar *const * string
[0]
#define QTEST_MAIN(TestObject)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.